Reputation: 2043
I have a CRA project that runs fine when i use react-scripts start
in development. But once I build react-scripts build
and then serve these files, I get this error
Uncaught TypeError: Cannot read property 'call' of undefined
I dont have any custom webpack config. I've tried to comment large areas of source code, and I still get this error trying to serve the build files.
Thanks for any help!
Upvotes: 1
Views: 2953
Reputation: 1082
@Barrard's solution worked for me.
If you're building a Create React App and don't want to eject the application, the following steps are how I updated my webpack config:
Add customize-cra
and react-app-rewired
[0]
Update your start
and build
scripts to use react-app-rewired
instead of react-scripts
[1]
There is no built in API to update the optimization.sideEffects
property, so we have to build our own [2]. Create a config-overrides.js
file where your package.json
is and add the following code in there:
const { override } = require("customize-cra");
const setOptimizationSideEffect = flag => config => {
config.optimization.sideEffects = flag
return config;
}
module.exports = override(
setOptimizationSideEffect(false)
);
[0] https://github.com/arackaf/customize-cra
[2] https://github.com/arackaf/customize-cra/issues/155#issuecomment-523958656
Upvotes: 0
Reputation: 2043
I found this answer, and it solved the issue.
https://stackoverflow.com/a/58628185/5231665
I just had to add this to the react-scripts
webpack.config.js
optimization: {
sideEffects: false,// <----- in production defaults to true if left blank
}
Upvotes: 3