Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
79
rated 0 times [  81] [ 2]  / answers: 1 / hits: 16998  / 7 Years ago, mon, september 4, 2017, 12:00:00

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

More From » requirejs

 Answers
50

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.


[#56585] Thursday, August 31, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaycoborionc

Total Points: 220
Total Questions: 106
Total Answers: 120

Location: Kenya
Member since Mon, Jun 14, 2021
3 Years ago
;