How to set .eslintrc to recognize 'require'?

Dan Nissenbaum picture Dan Nissenbaum · Jun 17, 2015 · Viewed 33.4k times · Source

I am new to ESLint, and I have successfully integrated ESLint with IntelliJ.

Out of the box, my integration of ESLint did not recognize node, but basic review of documentation made clear that by creating the configuration file named .eslintrc at the root of my project folder (with the proper IntelliJ setting to access this file) and setting "node":true, ESLint recognizes node (i.e., the following complete .eslintrc works).

// Contents of .eslintrc at root of project - support for Node and jQuery
{
  "env" : {
    "node" : true,
    "jquery" : true
  },
}

However, ESLint still does not recognize require(), as evidenced by this screenshot:

ESLint does not recognize <code>require()</code>

I have done my best in a reasonable amount of time searching for a solution to the basic question of how to get ESLint to recognize require(). In particular, I found a possible hint here, where it suggested to add "amd":false in (I presumed) the .eslintrc file - but no go.

This seems basic. How can I get .eslintrc to recognize require()?

(If, in your answer, you can provide insight how to cover more general cases, that would also be helpful. Thanks!)

Answer

Nick Avi picture Nick Avi · Jun 17, 2015

Adding amd to env inside .eslintrc will enable you to use define() and require(), as per the amd spec:

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