Skip to content
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

Production build failing: error from UglifyJs #30

Closed
dodas opened this issue Aug 31, 2016 · 7 comments
Closed

Production build failing: error from UglifyJs #30

dodas opened this issue Aug 31, 2016 · 7 comments

Comments

@dodas
Copy link

dodas commented Aug 31, 2016

Hello,

when i build (npm run build) fresh vuepack, it compiles OK.
however, when i import some module, for example jquery, prod. build fails with error:

ERROR in vendor.795f4ce9.js from UglifyJs
SyntaxError: Unexpected token: name (cache) [vendor.795f4ce9.js:18852,4]

Is there some configuration I can change to supress this error?

thank you very much.

@egoist
Copy link
Owner

egoist commented Aug 31, 2016

Can you provide more details on how you change the code, or a repo.

npm i -S jquery and import $ from 'jquery' just works for me.

@dodas
Copy link
Author

dodas commented Aug 31, 2016

Sorry, my bad, i had not fresh source.

What is creating this issue is module googlemaps-js-rich-marker. It is enough that this module is installed (don't have to be imported) for this issue to arise: npm i -S googlemaps-js-rich-marker

So now it is maybe not vuepack's failure. Could you guide me how to solve this? I am new to whole webpack/bundling/etc.

Thanks.

@egoist
Copy link
Owner

egoist commented Aug 31, 2016

Ok, seems googlemaps-js-rich-marker needs to be compiled to es5

It failed because that package is written in ES6 and uglifyjs doesn't understand ES6 syntax, and we do not compile files in node_modules folder by default.

Why it failed even if you didn't import googlemaps-js-rich-marker

Since vuepack splits all dependencies specified in package.json into a single vendor.xxx.js, googlemaps-js-rich-marker will always be compiled by webpack and bundled into vendor.xxx.js

How to fix

You should make babel-loader compile it to ES5. Checkout webpack.base.js.

By default it excludes node_modules and does not handle .es6 extension which that module uses, so the fix for you will be:

{
    test: /\.(js|es6)$/,
    loaders: ['babel'],
    // compile your app directory and some modules
    include: [/client/, /node_modules\/googlemaps-js-rich-marker/]
}

@dodas
Copy link
Author

dodas commented Aug 31, 2016

Thank you for detailed explanation, now I understand.
For the loaders part, wouldn't this be sufficient? Does it have any disadvantages?

{
  test: /\.js$/,
  loaders: ['babel'],
  exclude: [/node_modules/]
},
{
  test: /\.es6$/,
  loaders: ['babel']
}

@egoist
Copy link
Owner

egoist commented Aug 31, 2016

Maybe yours is better. .es6 should always be compiled to ES5

@dodas
Copy link
Author

dodas commented Aug 31, 2016

Great, don't you think this could be part od vuepack by default?

@egoist
Copy link
Owner

egoist commented Aug 31, 2016

Updated 👏

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

2 participants