Gulp, Vue, Webpack, Babel and Uncaught SyntaxError: Unexpected token import

拜拜、爱过 提交于 2019-12-05 18:26:02

You should remove query object from your webpack.config.js file, and create .babelrc file, that would contain this stuff.

{
  "presets": ["es2015"],
  "plugins": ["transform-runtime"],
  "comments": false
}

import issue seems to be solved in the comments above but there's one more.

.vue files do not seem to be written in standard JavaScript syntax. In order to import them, we need to somehow transform them to JavaScript.

While looking at the webpack.config.js you might notice, that files with .vue extension do not get transpiled in any way.

You can solve this problem with custom loaders. In this case, the loader you're looking for is vue-loader

Steps to solve the issue:

  • npm install --save-dev vue-loader
  • once done, try updating your webpack.config.js with following module section:

module: { loaders: [ { test: /\.js$/, loader: 'babel-loader', query: { presets: ['es2015'] } }, { test: /\.vue$/, loader: 'vue' }, ], }

More details:

Does it help in any way? If not, please let me know.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!