33

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

1

3 Answers 3

35

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.

Sign up to request clarification or add additional context in comments.

3 Comments

If my .eslintrc.js is used in a React project, should this line be added?
What worked for me was adding /* eslint-env node */ to the top of my .eslintrc.js, thus avoiding setting the environment to node
4

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' ], 

1 Comment

Please could you explain what is the reason for this error?
0

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

2 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.