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

Error from UglifyJs SyntaxError: Unexpected token: keyword (default) #216

Closed
kkomelin opened this issue Aug 8, 2016 · 5 comments
Closed

Comments

@kkomelin
Copy link

kkomelin commented Aug 8, 2016

We are trying to investigate why we are receiving the following error after importing vuejs-datepicker component into the clean vuejs webpack template:

ERROR in static/js/vendor.9868ef83011ecc7ffbea.js from UglifyJs
SyntaxError: Unexpected token: keyword (default) [./~/vuejs-datepicker/src/utils/DateLanguages.js:1,0]

Our test sequence:

  1. Create a new project https://github.com/vuejs-templates/webpack and install all dependencies:
vue init webpack my-project
cd my-project
npm install
  1. Import and include vuejs-datepicker into the App component.
npm install --save vuejs-datepicker

Then add the line to the js section of App.vue:

  import Datepicker from 'vuejs-datepicker'

After that add the following into the <template> section:

<datepicker></datepicker>
  1. Then build the app through the console:
npm run build

And you should notice the error in the console:

ERROR in static/js/vendor.9868ef83011ecc7ffbea.js from UglifyJs
SyntaxError: Unexpected token: keyword (default) [./~/vuejs-datepicker/src/utils/DateLanguages.js:1,0]

@charliekassel explained here the desirable behavior:

I don't really understand why this is an error as the files should be transformed to ES5 by babel before it gets to uglify.

Could you please advise us where to look for the bug?

Thank you so much,
Konstantin

@yyx990803
Copy link
Contributor

yyx990803 commented Aug 8, 2016

Likely because of this: https://github.com/vuejs-templates/webpack/blob/dist/template/build/webpack.base.conf.js#L53 which makes babel-loader skips anything from node_modules.

You can try adding vue-datepicker to the include array so that it's "whitelisted" to babel-loader.

@kkomelin
Copy link
Author

kkomelin commented Aug 8, 2016

Thank you @yyx990803 for your piece of advice.
However, it does not look like a plug&play approach if we should hardcode paths of third-party components in our webpack config every time. I want to believe that we can find a better way.

@yyx990803
Copy link
Contributor

@kkomelin this is because most npm modules export pre-compiled JS, but vue-datepicker is exporting raw *.vue files. If we apply babel to every npm module it will be hugely inefficient, so it's not something the template itself can accommodate for.

@kkomelin
Copy link
Author

kkomelin commented Aug 8, 2016

@yyx990803 This is the key. Then we should simply pre-compile vuejs-datepicker code and solve the problem. Hopefully. it is possible. I will discuss it with the maintainer of vuejs-datepicker.
Thank you very much for your help!

@kkomelin
Copy link
Author

@yyx990803 Thanks for your advice. I think we can close the issue.

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

3 participants