Not transpiling in prod mode?
I'm getting the following error when bundling in prod mode.
Timurs-MacBook-Pro:demo-app timur$ yarn prod
yarn prod v0.17.10
$ npm-run-all --sequential build serve
yarn run v0.17.10
$ NODE_ENV=production node ./config/scripts/build
Creating an optimized production build...
(node:84380) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
Failed to compile.
static/js/main.1ca47fa2.js from UglifyJs
Unexpected token: operator (>) [./~/get-own-enumerable-property-symbols/index.js:1,0][static/js/main.1ca47fa2.js:15690,25]
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "build" exited with 1.
error Command failed with exit code 1.
I searched for the error online and couldn't find anything, so then I looked at the code on the line referenced in the error and it was the following.
// lines 15690-15693
module.exports = object => {
return Object.getOwnPropertySymbols(object)
.filter(keySymbol => object.propertyIsEnumerable(keySymbol))
}
Does anyone know why it may not transpile? I ejected my config but haven't made any changes to the prod config besides adding a sass loader and excluding it from the url-loader. The app runs fine in dev mode
You are most likely importing files outside of appSrc (https://github.com/facebookincubator/create-react-app/issues/1234) -- this is not allowed default behavior. Since you ejected, you can tweak your webpack configuration to allow for this.
Okay, but I have been doing it without errors before, is it a new bug? Does this mean I need to move svgs into my src folder?
I'm only importing JavaScript from within src and node_modules
My apologies, it actually looks like you're depending on a node module get-own-enumerable-property-symbols which requires arrow functions. You need to switch packages or contact the package maintainer and ask that they ship compiled code.
Node modules are not compiled -- you can change this behavior but I advise against it (same line, include node_modules).
To figure out the culprit package, run npm ls get-own-enumerable-property-symbols (unless if you are depending on it).
Interesting but why would it transpile in dev mode?
This was the npm ls btw ty
[email protected]
└─┬ [email protected]
└── [email protected]
So you're saying I may need to include node_modules in the webpack config?
It's not being compiled in dev mode. The dev mode does not uglify code, only production. Uglify JS does not support ES6+ syntax, which is why this is blowing up.
Including node_modules is one solution, but I advise against it.
Perhaps you could compile just that package though, something like require.resolve('get-own-enumerable-property-symbols').
Okay yeah you're right. Where should I put that line?
Switch webpack.config.prod.js#171 to something like:
include: [paths.appSrc, require.resolve('get-own-enumerable-property-symbols')],
Your mileage may vary though. 😄
Okay I got the same error on a different line and require.resolve'd another package and it finally built but now that kinda messed up my app for some reason
And mileage at compile time or runtime ?
Messed up your app in what way? (this is why you shouldn't compile node_modules)
Mileage as in the location of that line.
I agree I wouldn't publish something not transpiled. It's bizarre the text of my app changed and it's still working fine in dev mode
What do you suggest?
https://github.com/timurtu/bootstrap-components
I believe you're just seeing the effects of the minifier mangling names. You can tune UglifyJsPlugin to shut that off (mangle: false).
Would the require.resolve have anything to do with it mangling source code? Do I have to sacrifice mangling names? Btw I realize transpiling node_modules may be out of scope for create-react-app and appreciate your help
No, the require.resolve is for something else. It looks (to me) you are turning your components into text using a library, which in turn is getting mangled names. Not sure if you can do anything about this, sorry!
You might be able to tell uglify to ignore certain names, but that's out of the scope of my knowledge.