Error: Cannot find module @rollup/rollup-win32-x64-msvc. npm has a bug related to optional dependencies (npm/cli#4828). Please try npm i again after removing both package-lock.json and node_modules directory.
at requireWithFriendlyError (E:\vue_project\soybean-admin\node_modules.pnpm\rollup@4.9.6\node_modules\rollup\dist\native.js:87:9)
at Object. (E:\vue_project\soybean-admin\node_modules.pnpm\rollup@4.9.6\node_modules\rollup\dist\native.js:96:48)
... 2 lines matching cause stack trace ...
at require$$0.Module._extensions..js (E:\vue_project\soybean-admin.pnp.cjs:17304:33)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at require$$0.Module._load (E:\vue_project\soybean-admin.pnp.cjs:17152:31)
at ModuleWrap. (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
[cause]: Error: Your application tried to access @rollup/rollup-win32-x64-msvc, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: @rollup/rollup-win32-x64-msvc (via "@rollup\rollup-win32-x64-msvc")
Required by: E:\vue_project\soybean-admin\node_modules.pnpm\rollup@4.9.6\node_modules\rollup\dist\

之前项目安装依赖后,可以正常运行,但是某一天安装依赖后,执行 npm run dev 运行项目时,提示上面的错误,判断原因应该为 npm 缓存问题,可以先清理缓存,然后删除 node_modulespackage-lock.json,再执行 npm i 重新安装依赖。

本人实施成功的解决方法就是:删除 nodejs,然后重新安装。

应该是删除 nodejs 后,其关联的 npm 缓存,也被删除了,然后重新安装之后,就可以正常使用了。

所以,正确解决方法应该是清理 npm 缓存之后,再重新安装依赖

当网络很差时,安装一些库的时候可能会安装失败,如果安装失败,则有必要先清理一下 npm 缓存,然后再重新安装。

# 强制清理缓存
npm cache clean --force
# 查看 npm 缓存保存的路径,如果提示不存在该命令,改用下面一句
npm cache dir
# 查看 npm 的配置信息,其中的 cache 字段就是 npm 缓存保存的目录路径
npm config list --json

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐