Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define is not defined (ESLint)

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
    }
}
like image 548
El Mac Avatar asked Sep 04 '17 13:09

El Mac


1 Answers

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.

like image 107
Louis Avatar answered Oct 19 '22 23:10

Louis