23

I'm getting 'module' is not defined error from the eslint in .eslintrc.js file.

What does this mean and how do I fix it?

vs code error message screenshot

lotaquestions
  • 241
  • 2
  • 3

3 Answers3

27

You need to add an environment setting inside your .eslintrc.js file, i.e.:

...
env: {
    node: true
},
...

That said, the error in the .eslintrc.js file itself should only appear in Visual Studio Code, because ESLint ignores file names that start with a dot per default.

GOTO 0
  • 42,323
  • 22
  • 125
  • 158
1

convert to es5 by writing export default { } instead of module.export = {}

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 04 '22 at 15:01
  • Tested with the as-of-the-moment lastest eslint version 8.48.0 and getting `"SyntaxError: Unexpected token 'export'"` after changing _.eslintrc_ to use `export default`. – Simo Kivistö Aug 30 '23 at 06:30
1

Be careful blindly setting the node environment in all projects. If the application is not going to be running on node (e.g. a browser application), don't set the whole project to use the node environment just to prevent linting errors in the config file. It's better to just not lint this file instead, or potentially set up a different set of rules for it.

To ignore it, just add the following to the .eslintrc.js file.

'ignorePatterns': [
  '.eslintrc.js'
],
Geraint Anderson
  • 3,234
  • 4
  • 28
  • 49