Skip to content

Error transforming bundle with 'uglify' plugin #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ammar91 opened this issue Oct 11, 2016 · 24 comments
Closed

Error transforming bundle with 'uglify' plugin #13

ammar91 opened this issue Oct 11, 2016 · 24 comments

Comments

@ammar91
Copy link

ammar91 commented Oct 11, 2016

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()
    ]
}
@ds8k
Copy link

ds8k commented Nov 30, 2016

Having the same issue, were you able to resolve this?

@TrySound
Copy link
Owner

I guess that's because of es2015 in dependencies code. Uglify supports only es5.

@mattpilott
Copy link

I also have this. My config is as follows, I am using the harmony branch though.

// Rollup plugins
import babel from 'rollup-plugin-babel';
import uglify from 'rollup-plugin-uglify';
import { minify } from 'uglify-js';

export default {
    entry: './app/scripts/framework/framework.js',
    dest: './app/scripts/framework/framework.min.js',
    format: 'iife',
    moduleName: 'UIKit',
    moduleContext: {
        './app/scripts/framework/parties/promise.js' : 'window',
        './app/scripts/framework/parties/fetch.js' : 'window'
    },
    plugins: [
        babel({
            exclude: ['./node_modules/**', './app/scripts/framework/parties/**'],
            "presets": [[
                "env", {
                    "targets": {
                        "chrome": 52
                    },
                    "modules": false
                }
            ]],
            "plugins": [
                "external-helpers"
            ]
        }),
        uglify({}, minify)
    ]
};

I get this error Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: operator (>)

Any help is much appreciated

@dotnetCarpenter
Copy link

@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
Copy link
Owner

@dotnetCarpenter What's exactly doesn't work?

@dotnetCarpenter
Copy link

@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.

import uglify from 'rollup-plugin-uglify'
import { minify } from 'uglify-js'
...
export default {
    entry: "js/src/main.js",
    plugins: [
        babel(babelrc()),
        uglify({}, minify)

Running the above through rollup gives me:

npm run rollup -- --config rollup.main.js

> timetracker-frontend@1.0.0 rollup /var/www/xmaspeer/timetracker/public
> rollup "--config" "rollup.main.js"

Compiling source to execute on chrome 55, firefox 50, safari 10
Treating 'app' as external dependency
Error transforming bundle with 'uglify' plugin: SyntaxError: Unexpected token: operator (>)
Error
    at new JS_Parse_Error (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1547:18)
    at js_error (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1555:11)
    at croak (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2094:9)
    at token_error (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2102:9)
    at unexpected (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2108:9)
    at expr_atom (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2635:9)
    at maybe_unary (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2797:19)
    at expr_ops (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2832:24)
    at maybe_conditional (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2837:20)
    at maybe_assign (eval at <anonymous> (/var/www/xmaspeer/timetracker/public/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2861:20)
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki

My .babelrc look like this (I also use env preset to only transpile the code that is not supported by my target browsers):

{
  "presets": [
    ["env",
    {
      "debug": false,
      "targets": {
        "browsers": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      },
      "modules": false
    }]
  ],
  "plugins": [
    "external-helpers"
  ]
}

OS: Ubuntu 16.04 (Linux 4.4.0-53-generic)
node: v7.2.1
npm: 3.10.10

@TrySound
Copy link
Owner

npm i mishoo/UglifyJS2#harmony

@dotnetCarpenter
Copy link

@matt3224 @TrySound At first it didn't work after installing mishoo/UglifyJS2#harmony. I had to manually delete the uglify-js folder and then install again. Now it works! 💃

@dotnetCarpenter
Copy link

@TrySound Perhaps you should update the README with this as it's not apparent.

@TrySound
Copy link
Owner

@dotnetCarpenter PR welcome.

@mattpilott
Copy link

mattpilott commented 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 or npm uninstall uglify-js rather than deleting the folder manually 👍

@Shyam-Chen
Copy link

Shyam-Chen commented Dec 15, 2016

same here

Error transforming bundle with 'uglify' plugin: SyntaxError: Invalid syntax: 0a.h

OS: Windows 10

@dotnetCarpenter
Copy link

dotnetCarpenter commented 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 a git 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 did yarn 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 your package.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 in node_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
Copy link
Owner

Report an issue in yarn.

@dotnetCarpenter
Copy link

@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
Copy link
Owner

You may always use npm again.

@jonataswalker
Copy link

For me what it worked was:

{
  "devDependencies": {
    "uglify-js": "git://github.com/mishoo/UglifyJS2#harmony"
  }
}

Instead of:

npm i mishoo/UglifyJS2#harmony

@piotr-cz
Copy link

This worked for me:

npm uninstall --save-dev uglify-js
npm install --save-dev mishoo/UglifyJS2#harmony

@aviddiviner
Copy link

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 the harmony-v2.8.0 tag, which is from around the time the last comments were made.

So, either

{"devDependencies": {"uglify-js": "git://github.com/mishoo/UglifyJS2#harmony-v2.8.0"}}

Or

npm install --save-dev mishoo/UglifyJS2#harmony-v2.8.0

@TrySound
Copy link
Owner

@aviddiviner harmony branch is released now as uglify-es

@dotnetCarpenter
Copy link

@TrySound I think you can safely close this issue as you have it documented in https://github.com/TrySound/rollup-plugin-uglify#warning

@dotnetCarpenter
Copy link

Or even better, switch to use uglify-es instead of uglify-js as a dependency.

@LuisSevillano
Copy link

For me what it worked was uninstall the plugin and install it again.
Thanks!

@TrySound
Copy link
Owner

@LuisSevillano yarn upgrade-interactive --latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants