Closed
Description
I have an Angular 2 sample app that's bundle up with Rollup, but it throws an error when using this plugin. It says
Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: name (AppComponent).
This is how my rollup.config.s looks like
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
export default {
entry: 'dist/app/main.js',
dest: 'dist/build.js', // output a single application bundle
sourceMap: false,
format: 'iife',
plugins: [
nodeResolve({ jsnext: true, module: true }),
commonjs({
namedExports: {
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
'node_modules/primeng/primeng.js': ['DialogModule']
},
include: ['node_modules/rxjs/**', 'node_modules/primeng/**']
}),
uglify()
]
}
Activity
ds8k commentedon Nov 30, 2016
Having the same issue, were you able to resolve this?
TrySound commentedon Nov 30, 2016
I guess that's because of es2015 in dependencies code. Uglify supports only es5.
mattpilott commentedon Dec 8, 2016
I also have this. My config is as follows, I am using the harmony branch though.
I get this error
Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: operator (>)
Any help is much appreciated
dotnetCarpenter commentedon Dec 13, 2016
@TrySound Can you elaborate on how to, use the UglifyJS harmony branch by passing its minify function to minify your code, described in https://github.com/TrySound/rollup-plugin-uglify#warning?
It doesn't work out of the box.
TrySound commentedon Dec 14, 2016
@dotnetCarpenter What's exactly doesn't work?
dotnetCarpenter commentedon Dec 14, 2016
@TrySound Uglify is not able to minify because of the es2015 syntax, when using the work-around, out of the box. I think we're all a bit clueless to how we can use the harmony branch of
uglify-js
. Well, maybe not @matt3224 but I for one don't know how to install a branch of a npm module.Running the above through rollup gives me:
My
.babelrc
look like this (I also use env preset to only transpile the code that is not supported by my target browsers):OS: Ubuntu 16.04 (Linux 4.4.0-53-generic)
node: v7.2.1
npm: 3.10.10
TrySound commentedon Dec 14, 2016
npm i mishoo/UglifyJS2#harmony
dotnetCarpenter commentedon Dec 14, 2016
@matt3224 @TrySound At first it didn't work after installing
mishoo/UglifyJS2#harmony
. I had to manually delete theuglify-js
folder and then install again. Now it works! 💃dotnetCarpenter commentedon Dec 14, 2016
@TrySound Perhaps you should update the README with this as it's not apparent.
TrySound commentedon Dec 14, 2016
@dotnetCarpenter PR welcome.
mattpilott commentedon Dec 14, 2016
Just a quick update from me, I have this working now which is awesome, since installing the harmony branch via the
npm i mishoo/UglifyJS2#harmony
@dotnetCarpenter i think its better to use either
npm un uglify-js
ornpm uninstall uglify-js
rather than deleting the folder manually 👍Shyam-Chen commentedon Dec 15, 2016
same here
Error transforming bundle with 'uglify' plugin: SyntaxError: Invalid syntax: 0a.h
OS: Windows 10
dotnetCarpenter commentedon Dec 15, 2016
@matt3224 I am using yarn and since uglify-js isn't in my dependency list but is a dependency of rollup-plugin-uglify, yarn won't let me uninstall uglify-js. Unfortunately,
yarn add --dev mishoo/UglifyJS2#harmony
does not install the correct branch, it just does nothing but report back everything is ok. I did agit diff
between the two uglify-js branches and then looked into the uglify-js folder to see if I had any of the differences, when I found none, I deleted the folder and didyarn add mishoo/UglifyJS2#harmony
to get the correct version.If I remember correctly, then
npm un uglify-js
just delete the uglify-js folder and update yourpackage.json
if you have it there. So a manual delete should be the same.When I
yarn add mishoo/UglifyJS2#harmony
, without having uglify-js innode_modules/
, the correct version of uglify-js will be installed. Had I done that initially, it might had work out from the beginning... But it's untested. E.g.yarn add --dev rollup-plugin-uglify mishoo/UglifyJS2#harmony
might work.TrySound commentedon Dec 15, 2016
Report an issue in yarn.
dotnetCarpenter commentedon Dec 15, 2016
@TrySound I know. But I'm pressed on time the next two weeks and got a lot of other priorities on my plate. I'll have to wait. But at least now, I'm not the only one with this information. ;)
TrySound commentedon Dec 15, 2016
You may always use npm again.
jonataswalker commentedon Dec 20, 2016
For me what it worked was:
Instead of:
piotr-cz commentedon Dec 28, 2016
This worked for me:
aviddiviner commentedon Jul 10, 2017
Just a note to anyone coming to this issue a few months later. That
harmony
branch has moved on quite a bit since it worked, so rather use theharmony-v2.8.0
tag, which is from around the time the last comments were made.So, either
Or
TrySound commentedon Jul 10, 2017
@aviddiviner harmony branch is released now as
uglify-es
dotnetCarpenter commentedon Jan 1, 2018
@TrySound I think you can safely close this issue as you have it documented in https://github.com/TrySound/rollup-plugin-uglify#warning
dotnetCarpenter commentedon Jan 1, 2018
Or even better, switch to use uglify-es instead of uglify-js as a dependency.
LuisSevillano commentedon Apr 12, 2018
For me what it worked was uninstall the plugin and install it again.
Thanks!
TrySound commentedon Apr 12, 2018
@LuisSevillano
yarn upgrade-interactive --latest