dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.
https://craco.js.org
Apache License 2.0
7.43k stars 499 forks source link

How to add polyfill using CRA5 with CRACO? #467

Closed kintz09 closed 1 year ago

kintz09 commented 1 year ago

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:

kintz09 commented 1 year ago

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.

dilanx commented 1 year ago

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