问题
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