Webpack 5 errors
If you're using the latest version of create-react-app with the @imtbl/XpansionChain-sdk module, you may see errors like this when trying to start up the app:
Why is this happening?
The reason for this error is that create-react-app uses a version of webpack greater than 5, which, unlike versions < 5, does not include Node.js polyfills by default. This means that they need to be configured manually for each module that requires them.
Normally, this involves updating the webpack config file inside a project, however, create-react-app uses another package called react-scripts to manage webpack (and other build dependencies). As we cannot update the webpack config within react-scripts, we will need to override it.
How to fix this
1. Install react-app-rewired
This package allows us to update the webpack config file to fix the polyfill node core module error.
Install with npm:
Install with yarn:
2. Install the missing dependencies
The following missing dependencies will have to be installed: crypto-browserify, stream-browserify, assert, stream-http, https-browserify, os-browserify, url, process
Install with npm:
Install with yarn:
3. Override the create-react-app webpack config file
This is how we override the webpack config file in react-scripts and tell it how to resolve the missing polyfill dependencies.
In the root folder of your project, create a new file called config-overrides.js
, and add the following code to it:
4. Override package.json to include the webpack configuration
Now, to implement the new config, we need to call react-app-rewired
instead of react-scripts
in the following scripts in our package.json:
start
build
test
This is what the package.json file looks like before:
This is what it looks like after:
Once you've done this, the development server should be up and running again.
How to deal with 'failed to parse source map' warnings
You will still have a large amount of failed to parse source map
from modules warnings. They can be ignored for now, however, should you want to get rid of them, you can disable them (see this discussion) by adding GENERATE_SOURCEMAP=false
to the start
script in package.json:
Last updated