在使用vite创建vue项目后,进入项目目录执行:
代码语言:javascript复制npm ls
出现如下报错:
代码语言:javascript复制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:workspacetypescriptcmds
├── 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:UsersCXWNAppDataLocalnpm-cache_logs2024-04-26T10_37_55_450Z-debug-0.log
该问题若不解决,运行npm run dev
则会报如下错:
failed to load config from G:workspacefrontendctosvite.config.js
error when starting dev server:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'vite' imported from G:workspacefrontendctosvite.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)
解决思路:
代码语言:javascript复制npm install @vitejs/plugin-vue@^5.0.4
进入项目目录执行npm ls
,结果如下:
cmds@0.0.0 G:workspacetypescriptcmds
├── @vitejs/plugin-vue@5.0.4
├── vite@5.2.10
└── vue@3.4.25