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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well it used to work when running
webpack-dev-server
directly so why doesn’t it work withwebpack serve
? After upgrading to webpack 5 I had to change towebpack serve
becausewebpack-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…
WEBPACK_DEV_SERVER
only for custom running, noWEBPACK_DEV_SERVER
inwebpack.config.js
, because we can’t know about it, you can use multi compiler mode, you can use env variables for this