Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

eslint

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?

like image 437
anna Avatar asked Aug 27 '19 10:08

anna


People also ask

How do you fix require is not defined in node js?

It happens when you declare your package type as module in your package. json . If you do this, certain CommonJS variables can't be used, including require . To fix this, remove "type": "module" from your package.


1 Answers

To specify environments in a configuration file, use the env key and specify which environments you want to enable by setting each to true. For example, the following enables the browser, es6 and Node.js environments:

In your .eslintrc.js file ;

...
env: {
   browser: true,
   node: true,    <<<<--- Add this
   es6: true
 },
...
like image 131
Rajan Maharjan Avatar answered Oct 22 '22 06:10

Rajan Maharjan