vue-awesome: Uncaught SyntaxError: Unexpected token import
First, I installed: npm install vue-awesome --save-dev
Then I added the following lines to main.js, based on the readme and example:
import Icon from 'vue-awesome/src/components/Icon.vue';
Vue.component('icon', Icon);
I get this error in the browser console:
> Uncaught SyntaxError: Unexpected token import Icon.vue?7cbb:36
Am I doing something incorrect? Thx!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 64 (20 by maintainers)
@jonnyparris
Nuxt’s server webpack config excludes all external modules from being transpiled in the server build. You need to whitelist vue-awesome (and it’s subpaths). Here’s how I fixed it for SSR:
Note: the first regex comes from the base nuxt server config.
I had similar (if not the same) problem, I’m using
webpack+vue-loader+babel. I have a.babelrcbut withoutadd-module-exportsplugin, but adding that to my own.babelrcdidn’t do me any good. I ended up importing the dist instead, worked like a charm.Cheers, fatbrain
Sorry, I forgot to mention one more thing. Vue’s
webpackproject template has excludednode_modulesfrom files to be transpiled by Babel so you have to excludevue-awesomefrom theexcludepattern inbuild/webpack.base.conf.jslike this:exclude: /node_modules(?![\\/]vue-awesome[\\/])/.@massada
Thanks for the solution. It seems that I should add a “Usage with Nuxt.js” section in the readme.
@Justineo This is cnpm’s problem. Package folder have been changed, so
exclude: /node_modules(?![\\/]vue-awesome[\\/])/does not work.@Pistos
Use
vue init webpackto start from scratch.After finished what
vue-cliask you to do, runnpm i vue-awesome.Modify
excludeconfig inbuild/webpack.base.conf.jsas I mentioned earlier.Import Vue-Awesome.
eg. in
src/App.vue:Add components into the template:
Run
npm run devand it should be working now.It seemed to be not working correctly with Vue 2.0’s webpack template. I’ll look into this guys.
@dcrystalj if you are testing with Jest, you should take a look at this: https://github.com/Justineo/vue-awesome#unit-testing-with-jest
I didn’t solve this.
my webpack configure file
I use “vue-awesome”: “^2.3.1” and I use vue ssr.
I do realize all that… Just saying how it could be easier - as obviously we are on an issue here, that people have
On Thu, Dec 22, 2016 at 4:27 PM GU Yiling notifications@github.com wrote:
^ this did the trick for me, along with
in the
.vuefile. (I am using the webpack template.)