Skip to content

Do not mutate the config object #1124

Closed
@dwjft

Description

@dwjft
  • Operating System: OS X
  • Node Version: 8.6
  • NPM Version: 5.4.2
  • webpack Version: 2.5.1
  • webpack-dev-server Version: 2.9.1
  • This is a bug
  • This is a feature request
  • This is a modification request

Code

let server;
const devServerConfig = {};
const startServer = () => {
  if (server) { server.close(); }
  // webpack plugin code, calls `startServer` on error
  server = new WebpackDevServer(compiler, devServerConfig);
  server.listen(8080);
};
startServer();
  // Server.js, line 33. this is the thrown error
  const validationErrors = webpack.validateSchema(optionsSchema, options);
  if (validationErrors.length) {
    throw new OptionsValidationError(validationErrors);
  }

Expected Behavior

  • When I start a webpack-dev-server, it should validate the options passed through correctly.
  • When I start a new webpack-dev-server, it should validate the options passed through correctly.

Actual Behavior

  • When I start a webpack-dev-server for the first time, the devServerConfig is mutated with a bunch of extra fields populated by the dev server itself.
  • When I try to start a new webpack-dev-server, the config object does not pass validation on line 33 of Server.js because it mutated the config object.

For Bugs; How can we reproduce the behavior?

See the code snippets.

For Features; What is the motivation and/or use-case for the feature?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions