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.

Assigning to free variables in the node environment should not trigger no-global-assign errors.

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.9.0
  • Node Version: 6.11.4
  • npm Version: 3.10.10

What parser (default, Babel-ESLint, etc.) are you using? Default.

Please show your full configuration:

module.exports = {
  env: {
    node: true,
  },
  rules: {
    'no-global-assign': ['error'],
  },
};

What did you do? Please include the actual source code causing the issue.

require = function () {};

What did you expect to happen? require is a free variable in Node, it’s not a global variable. (Try evaluating 'require' in global in a JavaScript file in Node. It evaluates to false.) Therefore, no error should be reported.

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

ESLint reports the following error:

1:1  error  Read-only global 'require' should not be modified  no-global-assign

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jacksonrayhamiltoncommented, Oct 16, 2017

Fair enough, especially considering CommonJS always requires some preprocessing. ESLint can’t possibly anticipate the infinitely many ways in which legitimate JS code could be preprocessed and how that could thus affect the semantics on the code it’s analyzing. CommonJS may be popular, but the “magic” involved doesn’t lend itself well to generic static analysis.

0reactions
platinumazurecommented, Oct 16, 2017

@jacksonrayhamilton I think this might be a case where you should use eslint-disable comments. We can’t cover every corner case and on rare occasions, a rule just might report something that is either contrary to more important requirements in your codebase, or outright incorrect.

I don’t think we can make a change here without having ESLint know too much about CommonJS scoping rules, which we don’t really want to do (for the purpose of trying to keep the library runtime-agnostic).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Environment Variables in Node.js for App Configuration ...
Learn why experienced Node.js developers use environment variables for app config and secrets, including how to manage default values and ...
Read more >
ESLint - "window" is not defined. How to allow global variables ...
I've tried adding something like this to the package.json file to have eslint allow "window" as a global variable, but I must be...
Read more >
Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
Read more >
How to Throw Exceptions in Node.js - Rollbar
Runtime errors can occur in a variety of ways. One example includes referencing an undefined variable, or passing the wrong type to an...
Read more >
Node.js Runtime Environment - App Engine - Google Cloud
Node.js version; Dependencies; Application startup; Environment variables ... release versions, but it will not automatically update the major version.
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