Webpack-dev-server: The WEBPACK_DEV_SERVER environment variable is not set when running "webpack serve"

Created on 19 Oct 2020  路  7Comments  路  Source: webpack/webpack-dev-server

  • 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
  • [x] 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.

Most helpful comment

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...

All 7 comments

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

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...

@bensampaio can you provide real use case, maybe we should restore this behavior, it will be easy

@evilebottnawi would this help: https://github.com/bensampaio/dev-server-issue ?

@bensampaio I recommend to use --env flags for this, but we can return this behavior, but this need to be fixed in webpack-cli

@evilebottnawi should I then open a new issue in webpack-cli?

@bensampaio yep please

Was this page helpful?
0 / 5 - 0 ratings

Related issues

movie4 picture movie4  路  3Comments

wojtekmaj picture wojtekmaj  路  3Comments

daryn-k picture daryn-k  路  3Comments

Jack-Works picture Jack-Works  路  3Comments

da2018 picture da2018  路  3Comments