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.

The WEBPACK_DEV_SERVER environment variable is not set when running "webpack serve"

See original GitHub issue
  • Operating System: macOS Catalina 10.15.7
  • Node Version: 12.18.3
  • NPM Version: 6.14.6
  • webpack Version: 5.1.3
  • webpack-dev-server Version: “3.10.3”
  • Browser: any
  • This is a bug
  • This is a modification request

Code

console.log(process.env.WEBPACK_DEV_SERVER);

Put the above in a webpack.config.js executed via:

webpack serve

Expected Behavior

I would expect the console.log to print true or 1. I am not sure what used to be the value for this environment variable but I am sure it used to be there.

Actual Behavior

undefined is printed.

How can we reproduce the behavior?

Simply place the above console.log inside any webpack.config.js that is run via webpack serve.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bensampaiocommented, Oct 20, 2020

Well it used to work when running webpack-dev-server directly so why doesn’t it work with webpack serve? After upgrading to webpack 5 I had to change to webpack serve because webpack-dev-server didn’t work anymore due to this issue: https://github.com/webpack/webpack-dev-server/issues/2029#issuecomment-707034614.

If this was expected behavior with the transition to webpack 5 then I would at least expect this to be documented in the migration guide instead of closing this issue as if was meant to be obvious that this is not possible…

1reaction
alexander-akaitcommented, Oct 19, 2020

WEBPACK_DEV_SERVER only for custom running, no WEBPACK_DEV_SERVER in webpack.config.js, because we can’t know about it, you can use multi compiler mode, you can use env variables for this

Read more comments on GitHub >

github_iconTop Results From Across the Web

The WEBPACK_DEV_SERVER environment variable is ...
When running webpack-dev-server the value of process.env.WEBPACK_DEV_SERVER is set to true . To Reproduce. Steps to reproduce the behavior:.
Read more >
Environment Variables
Setting up your env variable without assignment, --env production sets env.production to true by default. There are also other syntaxes that you can...
Read more >
node.js - Setting environment variables when running ...
Setting the environment variable NODE_ENV which is accessible through process.env.NODE_ENV at runtime, is specific to Node.js and is not ...
Read more >
Using environment variables with Webpack
A guide for setting up and using environment variables with Webpack and handling different values for Production and Development ...
Read more >
Passing Environment Variables Into Your Code With ...
I just set up a second Firebase database to be my staging ... My npm start script runs webpack-dev-server and configures the env...
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