dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.

Home Page:https://craco.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add polyfill using CRA5 with CRACO?

kintz09 opened this issue · comments

I was so excited to see a release candidate of CRACO with support for Create React App 5 and Webpack 5 has been released. Thank you so much to everyone who supported this important effort!

Now that it's released, could anyone provide some guidance on the proper way to add in the polyfills that were removed in Webpack?

module.exports={
  webpack: {
    configure: {},
  },
};

There's two polyfills I'm trying to add:

  • crypto (crypto-browserify)
  • stream (stream-browserify)

Ah, just came across a comment that gave me a great hint! For anyone else looking for a quick fix for the CRA5 polyfill issue, check out the CRACO config file below:

module.exports={
  webpack: {
    configure: {
      resolve: {
        fallback: {
          // Webpack 5, used in react-script v5, dropped support for built in node polyfills.
          // CRACO is being used to add these polyfills back into the webpack config until they are not needed.
          crypto: require.resolve("crypto-browserify"),
          stream: require.resolve("stream-browserify"),
        }
      }
    },
  },
};

If this is wrong, please let me know.

Looks like this is resolved so I'll close this issue.