定义未定义(ESLint) [英] Define is not defined (ESLint)

查看:318
本文介绍了定义未定义(ESLint)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到ESLint错误定义未定义。 (no-undef)。我相信,我只能在全局定义 define ,但这不应该被本地支持吗?

I keep getting an ESLint error 'define' is not defined. (no-undef). I believe, I could just define define globally, but shouldn't this be supported natively?

使用define的代码示例:

A code example using define:

define([], function () { // Error here!
    'use strict';
    ....

这是我的eslintrc.json:

This is my eslintrc.json:

{
    "env": {
        "shared-node-browser": true,
        "commonjs": true
    },
    "plugins": ["requirejs"],
    "extends": ["eslint:recommended"],
    "rules": {
        "indent": [
            "error",
            "tab"
        ],
        "linebreak-style": [
            "error",
            "windows"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ],
        "requirejs/no-invalid-define": 2,
        "requirejs/no-multiple-define": 2,
        "requirejs/no-named-define": 2,
        "requirejs/no-commonjs-wrapper": 2,
        "requirejs/no-object-define": 1
    }
}


推荐答案

在您的 .eslintrc.json 中设置:

"env": {
    "amd": true
},

打开 amd环境时,eslint将全局变量注册为 define require

When the "amd" environment is turned on, eslint registers globals for define and require.

我也将关闭 commonjs 环境,除非您确实混为一谈AMD和CommonJS在相同的代码库中。

I would also turn off the "commonjs" environment unless you really are mixing both AMD and CommonJS in the same code base.

这篇关于定义未定义(ESLint)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆