I am trying to optimize Create-react-app for production using following command:
npm run build
But it is giving me following error:
static/js/main.9c091e05.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [./~/http-build-query/index.js:16,0]
That might be because of module http-build-query but that module is too necessary for my app.
I have also tried yarn build and that is also giving me same error.
EDIT
I just knew by googling that ES6 syntax is not supported by npm run build. So the question is how to build ES6 syntax with npm run build ?
The reason this is happening is because the ES6 code in your node_modules folder is not handled by create-react-app - it assumes they have done this themselves (which they should).
Stop using that package, and find a better one.
Copy the code from the package to your own source files so babel has access to it
Eject create-react-app and customize the webpack config yourself, including a test for the node_modules folder (can really hinder your build time)
Overriding the webpack config from create-react-app to accomplish Option 3 without ejecting. Note this is complicated and Option 1 or Option 2 is what you should go for
Example of overriding can be found here: https://daveceddia.com/customize-create-react-app-webpack-without-ejecting/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With