Skip to content

webpack 5 install 'url' and 'events' as a dependency #1598

Closed
@debs-obrien

Description

@debs-obrien
  • Operating System: Mac OS
  • Node Version: v10.11.0
  • NPM Version: 6.4.1
  • webpack Version: 5
  • webpack-dev-server Version: 3.1.10
  • This is a bug
  • This is a modification request

Code

  // webpack.config.js
var path = require('path');

module.exports = {
    //...
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        compress: true,
        port: 9000,
    },
    resolve: {
        alias: {
            'url': false,
            'events' : false
        }
    }
};

Expected Behavior

Actual Behavior

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need these module and configure a polyfill for it.

If you want to include a polyfill, you need to install 'url'.
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.alias: { "url": false }

ERROR in (webpack)/hot/emitter.js 1:19-36
Module not found: Error: Can't resolve 'events' in '/Users/debbieobrien/webpack/node_modules/webpack/hot'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need these module and configure a polyfill for it.

If you want to include a polyfill, you need to install 'events'.
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.alias: { "events": false }
 @ (webpack)-dev-server/client?http://localhost:9000 226:21-51
 「wdm」: Failed to compile.

after adding the alias to the webpack.config I get this error

 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.resolve.alias should be one of these:
   object { <key>: string } | [object { alias?, name?, onlyModule? }]
   -> Redirect module requests
   Details:
    * configuration.resolve.alias['url'] should be a string.
      -> New request
    * configuration.resolve.alias['events'] should be a string.
      -> New request
    * configuration.resolve.alias should be an array:
      [object { alias?, name?, onlyModule? }]

For Bugs; How can we reproduce the behavior?

Run the webpack-dev-server in next branch

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