1

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 enter image description here

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!

6
  • share your code Commented Feb 26, 2020 at 5:36
  • Its a bit long to share. github.com/barrard/stock_panel Commented Feb 26, 2020 at 5:38
  • Checking the code!!! Commented Feb 26, 2020 at 5:44
  • I even just pushed up the source code all commented out And still see this error, I must have some cache error or something? Commented Feb 26, 2020 at 5:46
  • If you can add one line like config.optimization.minimize = false in webpack.config.js to disable the obfuscating function, it should very helpful for debugging, though from your screenshot I am not able to point out whether it is a logic problem or syntax problem. Commented Feb 26, 2020 at 9:12

2 Answers 2

3

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
}
Sign up to request clarification or add additional context in comments.

Comments

0

@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:

  1. Add customize-cra and react-app-rewired [0]

  2. Update your start and build scripts to use react-app-rewired instead of react-scripts [1]

  3. 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

[1] https://github.com/timarney/react-app-rewired#3-flip-the-existing-calls-to-react-scripts-in-npm-scripts-for-start-build-and-test

[2] https://github.com/arackaf/customize-cra/issues/155#issuecomment-523958656

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.