vue-cli: dynamic import() Syntax makes webpack throw an error
Version
3.3.0
Reproduction link
https://github.com/DragosRocsoreanu/VueCreateExample/tree/master/src
Environment info
Environment Info:
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
Binaries:
Node: 10.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.17763.1.0
npmPackages:
@vue/babel-helper-vue-jsx-merge-props: 1.0.0-beta.2
@vue/babel-plugin-transform-vue-jsx: 1.0.0-beta.2
@vue/babel-preset-app: 3.3.0
@vue/babel-preset-jsx: 1.0.0-beta.2
@vue/babel-sugar-functional-vue: 1.0.0-beta.2
@vue/babel-sugar-inject-h: 1.0.0-beta.2
@vue/babel-sugar-v-model: 1.0.0-beta.2
@vue/babel-sugar-v-on: 1.0.0-beta.2
@vue/cli-overlay: 3.3.0
@vue/cli-plugin-babel: ^3.3.0 => 3.3.0
@vue/cli-plugin-eslint: ^3.3.0 => 3.3.0
@vue/cli-service: ^3.3.0 => 3.3.0
@vue/cli-shared-utils: 3.3.0
@vue/component-compiler-utils: 2.5.0
@vue/eslint-config-prettier: ^4.0.1 => 4.0.1
@vue/preload-webpack-plugin: 1.1.0
@vue/web-component-wrapper: 1.2.0
babel-helper-vue-jsx-merge-props: 2.0.3
babel-plugin-transform-vue-jsx: 4.0.1
eslint-plugin-vue: ^5.0.0 => 5.1.0
vue: ^2.5.21 => 2.5.22
vue-eslint-parser: 2.0.3
vue-hot-reload-api: 2.3.1
vue-loader: 15.5.1
vue-router: ^3.0.1 => 3.0.2
vue-style-loader: 4.1.2
vue-template-compiler: ^2.5.21 => 2.5.22
vue-template-es2015-compiler: 1.8.1
vuex: ^3.0.1 => 3.1.0
npmGlobalPackages:
@vue/cli: Not Found
Steps to reproduce
vue create example
Select Lint,Vuex,Babel,Router
Select anything
CD example
npm run serve
What is expected?
To start the server and run normally
What is actually happening?
INFO Starting development server...
98% after emitting CopyPlugin
ERROR Failed to compile with 1 errors 11:18:18 PM
error in ./src/router.js
Module parse failed: Unexpected token (19:13)
You may need an appropriate loader to handle this file type.
| // which is lazy-loaded when the route is visited.
| component: function component() {
> return import(
| /* webpackChunkName: "about" */
| "./views/About.vue");
@ ./src/main.js 6:0-30 10:10-16
@ multi (webpack)-dev-server/client?http://192.168.0.10:8082/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
Apparently if I use YARN I won’t have this issue, so it’s NPM related issue Problem is with Router!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 28
- Comments: 35 (8 by maintainers)
Commits related to this issue
- fix: pin webpack version, fixes #3335 — committed to vuejs/vue-cli by sodatea 5 years ago
revert webpack to v4.28 https://github.com/webpack/webpack/issues/8656
I can confirm this, doing simply
yarn install
fixes thisI can confirm the workaround in the webpack issue doesn’t work. What worked for me was “downgrading” to
webpack@4.28.4
(be warned that this will addwebpack
as a direct dependency inpackage.json
):UPDATE: Doesn’t seem to work after all
see @lbogdan’s comment below instead (https://github.com/vuejs/vue-cli/issues/3335#issuecomment-456060780)
Workaround
People using yarn seem to be unaffected.
For users of npm: According to https://github.com/webpack/webpack/issues/8656#issuecomment-456010969 this works:
see the linked comment for an explantion of what’s going on.
Just released @vue/cli-service 3.3.1 on npm to pin webpack version for now. We’ll try to find a long-term solution for this issue later.
I can confirm that doing
fixes the issue.
same here. After upgrading to 3.3.0, my app is broken ☹️
I just bumped my project from webpack 3 to webpack 4, and met this problem. For me, the fix is install
since before I was using babel-plugin-syntax-dynamic-import. Then, in .babelrc
想问一下我路由是使用 (resolve) => { require([‘./components/stockAdjust/StockAdjustList’], resolve) }方式引入的,路由懒加载也有问题,首屏直接加载所有路由而不是,只加载用到的那一个。我已经把webpack设置为"4.28.4",了。为什么没有效果,还是首屏加载所有路由。没有懒加载
In the end I decided it was time to use yarn from now on.
@LinusBorg workaround with npm didn’t seem to work.
Steps taken:
Any workaround suggestions?