Search code examples
node.jseslint

'require' and 'process' is not defined in ESlint. problem with node?


I had an error in my pipeline in GitLab. I changed the settings in .eslint.json using information from StackOverflow. But I still have problem.

My .eslint.json looks like:

{
  "extends": "eslint:recommended",
  "rules": {
    "semi": ["warn", "never"],
    "quotes": ["warn", "single"],
    "no-console": ["off"]
  },
  "parserOptions": {
    "ecmaVersion": 9
  },
  "env": {
    "es6": true,
    "node": true,
    "browser": true,
    "amd": true
  },
  "globals": {
    "$": true,
    "require": true
    "process": true
  },
  "root": true
}

In env I added "adm": true and in globals I added "process": true and "require": true.

The errors are:

error 'require' is not defined no-undef

error 'process' is not defined no-undef

The file where is the errors are looks like this:

const qs = require("querystring");

const coEndpoint =
    process.env.NODE_ENV == "production"

So where is the problem? Is this a problem with env node? How can I fixed this?


Solution

  • Rename .eslint.json to .eslintrc.json or make sure that eslintConfig is specified in your package.json

    https://eslint.org/docs/user-guide/configuring

    Also make sure that eslint is started in the directory where your .eslintrc.json is and is not started with --no-eslintrc option.