Skip to content

Promise based webpack configs fail #1946

Description

@jspears
  • Operating System: OSX
  • Node Version:v8.10.0
  • NPM Version: 5.6.0
  • webpack Version:4.28.4
  • webpack-dev-server Version:3.5.0
  • This is a bug
  • This is a modification request

Code

When using a promise based configuration the error responds with

TypeError: Cannot read property 'bonjour' of undefined
    at createConfig (node_modules/webpack-dev-server/lib/utils/createConfig.js:13:12)
    at processOptions (node_modules/webpack-dev-server/lib/utils/processOptions.js:22:19)

// webpack.config.js
module.exports = new Promise(r=>setTimeout(r, 100, {}));

Expected Behavior

When using a promise to launch webpack-dev-server the

in

//processOptions.js 
function processOptions(config, argv, callback) {
  // processOptions {Promise}
  if (typeof config.then === 'function') {
///ERROR HERE -- argv is not passed ///
    config.then(processOptions).catch((err) => {
      // eslint-disable-next-line no-console
      console.error(err.stack || err);
      // eslint-disable-next-line no-process-exit
      process.exit();
    });

    return;
  }

Actual Behavior

Should be something like

function processOptions(config, argv, callback) {
  // processOptions {Promise}
  if (typeof config.then === 'function') {
///Fixed by passing argv.
    config.then( c =>processOptions(c, argv, callback)).catch((err) => {
      // eslint-disable-next-line no-console
      console.error(err.stack || err);
      // eslint-disable-next-line no-process-exit
      process.exit();
    });

    return;
  }

For Bugs; How can we reproduce the behavior?

A solution is above.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions