question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-undef fails with node.js global object

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.12.1
  • Node Version: 10.15.1
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration:

Configuration
{
  "env": {
    "node": true
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaVersion": 2018
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

global.my_value = 5;

if (my_value < 3) {
  // ...
}
eslint . --ext .js

What did you expect to happen? No error would occur as the nodejs environment is set.

What actually happened? Please include the actual, raw output from ESLint.

/path/to/my/index.js
   3:5  error  'my_value' is not defined      no-undef

Are you willing to submit a pull request to fix this bug? No, I lack the experience with eslint internal code to reliably do so.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Jan 30, 2019

Personally I don’t think this change would be worth the complexity, because:

  • ESLint currently isn’t aware that global represents the global object in Node. The node env just enables some specific globals such as module, global, and exports (and also some unrelated parser options), but there isn’t any concept of “assignments to this value will create a property on the global object”.
  • This won’t create a global if someone has reassigned global.global to something other than the global object.
  • Determining whether a particular global is present at any given point is undecidable, since a property could also be conditionally deleted from the global object (or deleted in another file). On the other hand, determining whether a non-global variable is in scope is statically decidable for strict mode code.
0reactions
fregantecommented, Apr 3, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint doesn't recognize node.js's 'global' object
The global object is part of Node.js. It is not specific to Jest and therefore it's not included in the jest environment.
Read more >
no-undef - ESLint - Pluggable JavaScript Linter
This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for ...
Read more >
Global objects | Node.js v19.3.0 Documentation
These objects are available in all modules. The following variables may appear to be global but are not. They exist only in the...
Read more >
LLVM Language Reference Manual
Global values are represented by a pointer to a memory location (in this case, a pointer to an array of char, and a...
Read more >
Expose Global Variables, Methods, and Modules in JavaScript
Expose Global Variables, Methods, and Modules in JavaScript. ... the function is not defined: error 'setJavaPresent' is not defined no-undef.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found