使用@vue/cli4.2.3 create初始化一个项目后,运行命令一直报如下错误,提示ansi-sytles找不到
解决过程:
1、以为是缺少提示中的包,直接按照提示安装ansi-sytles,无果。
事情远没有想的这么简单
2、rm -rf node_modules 再 npm install,无果
3、rm -rf node_modules 再npm cache clean -f清空缓存,再 npm install,无果
4、怀疑是自己电脑环境,找同事初始化了一个项目打包给我,运行npm run serve,还是同样的报错
5、有点绝望了,看到网上说@vue-cli4会自己升级sass-loader,于是升级了sass-loader,但是会提示node-sass安装不上,(原因是node-sass要从github上下载包,国内网络环境导致经常安装不上)想办法装上了node-sass,依旧无果~
对应攻略:https://blog.csdn.net/qq_39953537/article/details/102759821
6、尝试将@vue/cli降级后再初始化出来一个项目,成功!
以下是前五步出错阶段一直存在的报错提示:
$ npm run serve
temp@0.1.0 serve E:\test\temp
vue-cli-service serve
INFO Starting development server...
WARN A new version of sass-loader is available. Please upgrade for best experience.
ERROR Error: Cannot find module 'ansi-styles'
Error: Cannot find module 'ansi-styles'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (E:\node_modules\eslint\node_modules\chalk\index.js:3:18)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (E:\node_modules\eslint\lib\formatters\codeframe.js:7:15)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! temp@0.1.0 serve: vue-cli-service serve
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the temp@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:\MyData\ex_zengfr\AppData\Roaming\npm-cache_logs\2020-03-12T06_57_36_529Z-debug.log