I have installed eslint in my machine and i have used visual studio code i have certain modules and process to be exported When i try to use "module" or "process" it shows it was working fine before.

[eslint] 'module' is not defined. (no-undef) [eslint] 'process' is not defined. (no-undef) 

and here is my .eslintrc.json

{ "env": { "browser": true, "amd": true }, "parserOptions": { "ecmaVersion": 6 }, "extends": "eslint:recommended", "rules": { "no-console": "off", "indent": [ "error", "tab" ], "linebreak-style": [ "error", "windows" ], "quotes": [ "error", "single" ], "semi": [ "error", "always" ] } 

}

I want to remove this error

2

6 Answers

You are probably trying to run this in node environment.

The env section should look like this:

"env": { "browser": true, "amd": true, "node": true }, 
4

In your ESLint config file, simply add this:

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

That should fix the "module" is not defined and "process" is not defined error.

That assumes you are running in a Node environment. There is also the browser option for a browser environment. You can apply both based on your need.

If you want to prevent ESLint from linting some globals then you will need to add the specific global variables in the globals section of the config.

globals: { window: true, module: true } 
0

You need to tell eslint that you are in a Node environment. My favourite way to do this for one-off files like gulpfile.js is to include this comment at the top:

/* eslint-env node */ 
6

I think you can just rename all your CommonJS config files to have .cjs as their extension and then add this to eslintrc.cjs:

module.exports = { // ... env: { // If you don't want to change this to `node: true` globally es2022: true, }, // then add this: overrides: [ { files: ['**/*.cjs'], env: { node: true, }, }, ], } 
2

In my case below codes solve the issues

eslintrc.cjs

module.exports = { env: { browser: true, es2020: true,es2022: true }, extends: [ 'eslint:recommended', 'plugin:react/recommended', 'plugin:react/jsx-runtime', 'plugin:react-hooks/recommended', ], overrides: [ { files: ['**/*.cjs'], env: { node: true, }, }, ], parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, settings: { react: { version: '18.2' } }, plugins: ['react-refresh'], rules: { 'react-refresh/only-export-components': 'warn', "react/prop-types": "off" }, }

in my .eslintrc.cjs

module.exports = { env: { browser: true,es2020: true }, /*rest of code goes here*/ } 

i've added node property to the env object and set it to true node: true so the final result would be

module.exports = { env: { browser: true, node: true, es2020: true }, /*rest of code goes here*/ } 

and now there's no issue

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.