创建vue项目安装element-plus 依赖以及element-plus 插件, 无法启动服务
提示如下:
......
Module not found: Error: Package path ./lib/locale/lang/zh-cn is not exported from package ...项目路径\node_modules\element-plus (see exports field in ...项目路径\node_modules\element-plus\package.json)
ERROR in ./src/plugins/element.js 2:0-48
Module not found: Error: Package path ./lib/theme-chalk/index.css is not exported from package ...项目路径\node_modules\element-plus (see exports field in ...项目路径\node_modules\element-plus\package.json)
@ ./src/main.js 5:0-51 7:0-18
ERROR in ./src/plugins/element.js 3:0-56
Module not found: Error: Package path ./lib/locale/lang/zh-cn is not exported from package ...项目路径\node_modules\element-plus (see exports field in ...项目路径\node_modules\element-plus\package.json)
@ ./src/main.js 5:0-51 7:0-18
原因
安装的element-plus 2.4.2 依赖, 里面部分代码路径更新了, 导致插件中的配置有问题.
解决方法
源文件 ...项目路径\src\plugins\element-plus.js
import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
import locale from 'element-plus/lib/locale/lang/zh-cn'
export default (app) => {
app.use(ElementPlus, { locale })
}
修改
import ElementPlus from 'element-plus'
import 'element-plus/theme-chalk/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn'
export default (app) => {
app.use(ElementPlus, { locale })
}