Define is not defined (ESLint)

♀尐吖头ヾ 提交于 2019-12-10 00:53:25

问题


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?

A code example using define:

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

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
    }
}

回答1:


In your .eslintrc.json set:

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

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

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



来源:https://stackoverflow.com/questions/46038027/define-is-not-defined-eslint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!