Skip to content

Webpack v5 support #584

@pi0neerpat

Description

@pi0neerpat

Polyfils aren't no longer injected for the latest version of webpack. GatsbyJS is already using webpack v5. I'd also like to upgrade my own umd package which uses WC.

Example error message during webpack build:

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 this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }`

Issue 1: Gotta have those polyfils

Rather than force every app to manually add these packages, they should already be included in the WC packages.

Issue 2: Using Node.JS modules in a browser application

Is this a concern? I read that its not recommended but haven't researched enough to know for sure. Similar issue in another package: angular/angular-cli#20819 (comment)

Temporary Solution

In your application that uses Webpack V5, make the following changes

yarn add stream-browserify stream-http crypto-browserify https-browserify os-browserify util url assert

Then update your webpack config. Here's a GatsbyJS example:

// gatsby-node.js

exports.onCreateWebpackConfig = ({ stage, actions }) => {
  actions.setWebpackConfig({
    resolve: {
      fallback: {
        util: require.resolve(`util/`),
        url: require.resolve(`url/`),
        assert: require.resolve(`assert/`),
        crypto: require.resolve(`crypto-browserify`),
        os: require.resolve(`os-browserify/browser`),
        https: require.resolve(`https-browserify`),
        http: require.resolve(`stream-http`),
        stream: require.resolve(`stream-browserify`),
      },
    },
  })
}

See stack overflow for more info

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions