問題
在最新的Vue 3.2+vue-cli 4.5構建的項目中,起初按照之前老版vue3引入element plus的方法,在main.js中使用如下語句引入element plus的所有樣式文件:
import 'element-plus/lib/theme-chalk/index.css';
但是出現報錯:
Failed to compile. ./src/main.js Module not found: Error: Can't resolve 'element-plus/lib/theme-chalk/index.css' in 'E:\sourceFiles\map-survey\src'
由於之前都是這樣引入的,報錯時覺得很離譜
解決
解決思路也很簡單,既然自己已經安裝了element-plus依賴,卻找不到文件,大概率是路徑變了。於是手動翻了下node-modules,發現果然整個theme-chalk文件夾都被挪了位置。
由此,將引入樣式的語句改為:
import 'element-plus/theme-chalk/index.css'
即可解決報錯。希望能幫到剛接觸vue+element的朋友