问题:Error: Cannot find module '@vue/vue-loader-v15/package.json'及npm ERR! demo@0.1.0 serve: `vue-cli-service serve --mode development`项目启动报错
由于最近新入职一家公司,接手的项目技术栈是Vue2,拿到项目后就npm install, 项目安装依赖都一切正常,但一旦npm run serve就报错:
INFO Starting development server...
ERROR Error: Cannot find module '@vue/vue-loader-v15/package.json'
Require stack:
- D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\config\base.js
- D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\Service.js
- D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\bin\vue-cli-service.js
Error: Cannot find module '@vue/vue-loader-v15/package.json'
Require stack:
- D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\config\base.js
- D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\Service.js
- D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\bin\vue-cli-service.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\config\base.js:65:23
at D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\Service.js:268:40
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\Service.js:268:26)
at Service.resolveWebpackConfig (D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\Service.js:272:48)
at PluginAPI.resolveWebpackConfig (D:\chaotiqiyuan\12_H5_web\node_modules\@vue\cli-service\lib\PluginAPI.js:132:25)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo@0.1.0 serve: `vue-cli-service serve --mode development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! D:\Program Files\nodejs\node_cache\_logs\2022-08-18T09_45_09_414Z-debug.log
我以为是安装依赖的问题,于是删除node-moudels,删掉缓存,使用命令 npm cache clean --force,
删除 C:\Users\
{账户}\下的 .npmrc
文件,重新npm install和npm run serve,没有效果,我再次尝试上述操作并卸载node,重新安装node后再次尝试依然无效;于是在网上找了很多解决办法,但也都只说要删除node-moudels并重新安装实际问题并没有解决,于是我尝试搜索vue-loader的问题,终于找到一个办法,总结如下:
第一步删除node-models
第二步更新npm: npm install npm@latest -g
第三步:npm i --save-dev vue-loader-v15
第四步:删除C盘或D盘错误日志(只是占内存,不删也可以)
第五步:重新npm install
第六步:运行npm run serve
完美解决!