ESLint - 'process' is not defined

56,422

Solution 1

When I got error I had "browser": true instead of "node": true.

I have fixed this with following config for .eslintrc.json file-

{
    "env": {
        "node": true,
        "commonjs": true
    },
    "extends": "eslint:recommended",
    "rules": {
        "indent": [
            "error",
            "tab"
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    },
    "parserOptions": {
        "ecmaVersion": 2015
    }
}

Thanks @FelixKling and @Jaromanda X for quick responses.

Solution 2

Adding "node": "true" to an existing list of environments will do the job, too

"env": {
        "node": true,
        "commonjs": true,
        "browser": true,
        "es6": true
       }

Solution 3

Add .eslintrc file to root of your project (if you don't already have one) and define globals to ignore

{
    "globals": {
        "process": true
      }
}

Make sure you use process.env though out the project but only in a single configuration file. Consider adding no-process-envrule.

https://eslint.org/docs/rules/no-process-env

Solution 4

If you have eslint installed, add env: { node: true } to the .eslintrc.js file

Solution 5

this config helped me and can help others too

{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true,
      "modules": true
    },
    "ecmaVersion": 2020,
    "sourceType": "module",
    "useJSXTextNode": true,
    "warnOnUnsupportedTypeScriptVersion": false
  },
  "root": true,
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "commonjs": true
  },
  "extends": [ "eslint:recommended"],
  },
}
Share:
56,422
ArunKolhapur
Author by

ArunKolhapur

I am a gonecase developer having no idea what future holds. Please visit my social spaces and I would really appreciate if you leave me a message. After all, social connections is what all it is about.

Updated on July 08, 2022

Comments

  • ArunKolhapur
    ArunKolhapur almost 2 years

    I am using ESLinter for a simple node project. Below is the only code I have in index.js:

    const express = require('express');
    const app = express();
    
    app.get('/', (req, res) => {
        res.send({
            hi: 'there'
        });
    });
    
    const PORT = process.env.PORT || 5000;
    app.listen(PORT);
    

    I am using VSCode editor. It automatically runs ESLint for JS code.

    In the IDE, I see below error for last but one line -

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

    Any Idea what's wrong?

  • Mark Swardstrom
    Mark Swardstrom about 5 years
    This got rid of my ESlint 'URL' is not defined, too.
  • try_catch
    try_catch about 2 years
    In my case I was missing the node: true on my env eslint config file.
  • Josh
    Josh about 2 years
    Adding the "node" : true worked for me also with this issue.