ERROR in bundle.js from UglifyJs SyntaxError: Unex

2019-07-12 09:55发布

问题:

I have my app made with Reactjs.

I'm gettint this error when I try to run npm run-script build:

ERROR in bundle.js from UglifyJs
SyntaxError: Unexpected token: name (x)  [./react/stores/UserStore.js:52,20]

ERROR in bundle.js from UglifyJs
SyntaxError: Unexpected token: name (x)  [./react/stores/UserStore.js:52,20]

The error is thrown twice. And the line of the file that is poiting is commented! And now I try without those lines and I'm still getting the same error. But this is the first time that I have this error, don't know why, and i haven't touched that file in weeks...

Any idea?

回答1:

Well, in my case was that I didn't have babel-preset-es2015 so:

  1. npm install --save-dev babel-preset-es2015
  2. Add es2015 to webpack-production.config.js, like this: ['es2015', 'es2016', 'react']

The Uglify will work with es6 code (es6 -[babel preset es2015]-> es5 -> webpack with uglify plugin -> done)