在使用vite创建vue项目后,进入项目目录执行:
shell
npm ls
出现如下报错:
text
npm error code ELSPROBLEMS
npm error missing: @vitejs/plugin-vue@^5.0.4, required by cmds@0.0.0
npm error missing: vite@^5.2.0, required by cmds@0.0.0
npm error missing: vue@^3.4.21, required by cmds@0.0.0
cmds@0.0.0 G:\workspace\typescript\cmds
├── UNMET DEPENDENCY @vitejs/plugin-vue@^5.0.4
└── UNMET DEPENDENCY vue@^3.4.21
npm error A complete log of this run can be found in: C:\Users\CXWN\AppData\Local\npm-cache\_logs\2024-04-26T10_37_55_450Z-debug-0.log
该问题若不解决,运行npm run dev
则会报如下错:
text
failed to load config from G:\workspace\frontend\ctos\vite.config.js
error when starting dev server:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite' imported from G:\workspace\frontend\ctos\vite.config.js.timestamp-1714128992789-605d83da2d988.mjs
at packageResolve (node:internal/modules/esm/resolve:854:9)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1157:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
at link (node:internal/modules/esm/module_job:86:36)
解决思路:
shell
npm install @vitejs/plugin-vue@^5.0.4
进入项目目录执行npm ls
,结果如下:
text
cmds@0.0.0 G:\workspace\typescript\cmds
├── @vitejs/plugin-vue@5.0.4
├── vite@5.2.10
└── vue@3.4.25