Skip to content

Do not mutate the config object #1124

Closed

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?

Activity

  1. shellscape commented on Sep 28, 2017

    @shellscape
    Contributor

    @dwjft please provide the structure of your options before and after the first run, only then will we know what to look for specifically.

  2. dwjft commented on Sep 28, 2017

    @dwjft
    Author

    I mean, you can figure that out by just reading the snippet of code.

    const config = {};
    new WebpackDevServer(compiler, config);
    console.log(config);
    /**
     * output: 
     * config: {
        reportTime: false,
        reporter: [Function: defaultReporter],
        log: [Function: bound bound consoleCall],
        warn: [Function: bound bound consoleCall],
        error: [Function: bound bound consoleCall] }
    */
  3. shellscape commented on Sep 28, 2017

    @shellscape
    Contributor

    @dwjft as reporter you should provide all available info. thanks for the paste, we'll look into what's modifying that and see what we can put in place.

  4. added this to the milestone on Sep 30, 2017
  5. shellscape commented on Oct 13, 2017

    @shellscape
    Contributor

    This is going to land in the beta branch in the next week or so, and has been implemented in the refactor-lib branch that is currently WIP. If someone steps up to fix this in the 2.9.x branch, we'll happily review a PR, but our energies right now are being directed towards getting 3.0.0@beta out the door.

  6. removed this from the 3.1.6 milestone on Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions