Cannot find module 'xxx',錯誤解決方法

錯誤信息
在這裏插入圖片描述

Cannot find module '@/views/login/index'
Failed to resolve async component default
vue-router.esm.js:1897 Error: Cannot find module '@/views/login/index'
at webpackEmptyContext (index.js:39)
at permission.js:90

解決方法
進入router中的index.js

component: () => import('@/views/login/index'),

改爲

component: (resolve) => require(["@/views/login/index"], resolve),

如果是動態路由則

export const loadView = (view) => { // 路由懶加載
  return () => import(`@/views/${view}`)
}

改爲

export const loadView = (view) => { // 路由懶加載
  return (resolve) => require([`@/views/${view}`], resolve)
}

錯誤原因是老外修改了webpack打包邏輯,webpack4中動態import不支持變量方式,
該修改對於生產環境無影響,只在開發環境有問題

如果解決了你的問題,請回來點贊哦。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章