laravel-mix: UglifyJs: Unexpected token: operator (>)
When running npm run production I get the following error:
/js/listing.js from UglifyJs
Unexpected token: operator (>) [./~/bootstrap/js/src/dropdown.js:11,0][/js/listing.js:3302,23]
I’ve tried deleting node_modules without any luck, same goes for installing:
yarn add --dev git+https://github.com/mishoo/UglifyJS2.git#harmony
Arrow function seem to be the issue, line 11 of dropdown.js is:
const Dropdown = (($) => {
I don’t have a .babelrc file.
laravel-mix@0.11.4
Node: v7.9.0
NPM: 4.5.0
macOS: 10.12.4
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 25
- Comments: 46 (10 by maintainers)
Same problem.
For
webpackv3 onwards the aliasing forUglifyJSis changed. Refer https://github.com/webpack-contrib/uglifyjs-webpack-plugin.So for me modifying my
webpack.config.jsfrom to usenew UglifyJsPlugin()rather thannew webpack.optimize.UglifyJsPlugin()fixed the issue.Reference: https://github.com/joeeames/WebpackFundamentalsCourse/issues/3#issuecomment-352541826
@JeffreyWay: Could you re-open this until it’s resolved?
My babel ES2015 preset was excluding /node_modules/ and this would end up not converting some newer modules before uglify saw the code and it choked on the arrow function like the OP title, adding node_modules back solved the issue here (Webpack)
@ipa1981
rm -rf node_modulesdirectory,rm package-lock.jsonandnpm install. See if that works.When upgrading from 0.* to 1.* I had to do that to make things work.
Also, check if your npm is now
5.0.4.5.0.3had problems with some packages/dependencies not being installed.https://www.npmjs.com/package/vue-strap
Shouldn’t uglify work out of the box, since it’s enabled by default in production?
@ruchern, thanks for ideas! I just tried many different things. And it seems CommonJS syntax:
finally works with latest
vue-loader13.0.0 (I had 12.2.1 on the time testing).So at the moment it looks like everything is fine - both
watchandproductionscripts compiles.@ruchern thanks a lot, seems this works! Not exactly as you proposed, but in original
app.jsfile I had to change this:to this
I don’t know what’s the difference however, but this goes to compile.
@iraklisg Nope. upgraded to 1.0.7, still the same:
I’m about to tag a new release that bumps the Uglify version, so I think that should fix this.
Getting the same when using a package that has
=> {}. Seems like UglifyJs is working on it https://github.com/mishoo/UglifyJS2/issues/448I’m still getting errors for shorthand closures.
@JeffreyWay perhaps swap from JSUglify to https://github.com/babel/babili ? Babili supports ES6
@ipa1981 I have fixed your issue.
In your
app.jsfile,Use this instead of anything else.
@balthild, all upgrading to
laravel-mix@1.0.7solved the problem for me