vue3+vite更新版本后報錯:Cannot read property 'modules' of undefined

安裝新依賴之后重新運行項目,發現頁面打不開,控制台報錯如上,首先看到Error出現在App.vue中,但是沒裝依賴之前項目是正常運行的,通過卸載依賴、重裝依賴、頁面清空等操作發現項目都跑不起來。遂去Vite的issue中查找,發現了這條:TypeError: ssrContext is undefined · Issue #6043 · vitejs/vite (github.com)
I had tried to replicate your issue without succes. is correct should not happen in spa app.
vite 2.7 requires vue plugin version 1.10 and up \
意思是Vite 2.7以上的版本需要vue plugin高於1.10
解決方案:
- 手動更改
@vitejs/plugin-vue的版本 高於1.10,或者刪掉對應包管理工具的.lock文件 - 重裝依賴,重啟項目
