Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint - 'process' is not defined

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?

like image 720
ArunKolhapur Avatar asked Jun 17 '18 05:06

ArunKolhapur


People also ask

How do you fix process is not defined?

To solve the "Uncaught ReferenceError: process is not defined" in React, open your terminal in your project's root directory and update the version of your react-scripts package by running npm install react-scripts@latest and re-install your dependencies if necessary.

How do I turn off rule ESLint?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.


2 Answers

Thanks @FelixKling and @Jaromanda X for quick responses.

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

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

like image 137
ArunKolhapur Avatar answered Sep 22 '22 23:09

ArunKolhapur


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

"env": {         "node": true,         "commonjs": true,         "browser": true,         "es6": true        } 
like image 42
crtag Avatar answered Sep 26 '22 23:09

crtag