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.

`prefer-destructuring` conflicts with Webpack replacements of `process.env`

See original GitHub issue

Webpack can replace Node-like process.env.ENV_STUFF with the actual environment variable provided at build time: https://webpack.js.org/plugins/environment-plugin/

This process is pretty “dumb” as it’s a simple search and replace of exactly process.env.${variableName} and nothing else. This means destructuring isn’t possible with process.env.

More context found in: https://github.com/vercel/next.js/issues/19420

What rule do you want to change?

prefer-destructuring

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings

How will the change be implemented? (New option, new default behavior, etc.)?

New default I’d assume

Please provide some example code that this change will affect:

const ENVIRONMENT = process.env.ENVIRONMENT

What does the rule currently do for this code?

It suggests fixing it to this, breaking webpack’s replacement.

const {ENVIRONMENT} = process.env;

What will the rule do after it’s changed?

Ignore process.env destructuring. It’d be great to even suggest the opposite (Avoid destructuring of process.env), but maybe that’s asking too much.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
nzakascommented, Aug 12, 2021

We generally try to avoid ultra-specific exceptions like this. This seems like a good case for using a disable comment instead.

0reactions
njbmartincommented, Nov 17, 2021

Just ran into this issue myself, I definitely prefer destructuring objects and don’t particularly want to add comments to disable (as it’s in a number of files.

As an example, having to do this:

/*eslint-disable */
const KLAVIYO_LIST_ID = process.env.KLAVIYO_LIST_ID;
const KLAVIYO_API_KEY = process.env.KLAVIYO_API_KEY;
const FAUNADB_SECRET = process.env.FAUNADB_SECRET;
const FAUNADB_DOMAIN = process.env.FAUNADB_DOMAIN;
/* eslint-enable */

It would be great if there was a way to add something in the eslint config to ignore process.env for this rule.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WARNING in DefinePlugin Conflicting values for 'process.env ...
Solution. Make sure, mode in your webpack. config object (or in the CLI command, which overrides it in the config object) is the...
Read more >
EnvironmentPlugin | webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
A Dead Simple Guide to Using Environment Variables in Your ...
A Dead Simple Guide to Using Environment Variables in Your Front End with Webpack. If you are using APIs in your React app,...
Read more >
How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
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