填坑之旅:win10 unapp vue-cli ERROR in Cannot find module 'node-sass'
ERROR in Cannot find module 'node-sass'
使用vue-cli生成的uniapp项目,npm run dev报错:
ERROR in Cannot find module 'node-sass'
其实在用uniapp的模板生成出来的项目,其实是直接可运行(H5和小程序都是正常的)
但我本身添加的代码中可能有sass的东西,于是使用npm执行安装
npm install node-sass
又报错:
gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\find-visualstudio.js:122:47) gyp ERR! stack at D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\find-visualstudio.js:75:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\find-visualstudio.js:363:14) gyp ERR! stack at D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\find-visualstudio.js:71:14 gyp ERR! stack at D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\find-visualstudio.js:384:16 gyp ERR! stack at D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at D:\nodejs\node_global\node_modules\node-sass\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (child_process.js:315:5) gyp ERR! stack at ChildProcess.emit (events.js:314:20) gyp ERR! stack at maybeClose (internal/child_process.js:1047:16) gyp ERR! System Windows_NT 10.0.19045
很好奇,这个node-sass和visualstudio的关系?继续找解决方案,找到原因和解决办法:
主要是windows平台缺少编译环境,
- 先运行: npm install -g node-gyp
- 然后运行:运行 npm install --global --production windows-build-tools 可以自动安装跨平台的编译器:gym注:第二句执行下载好msi文件卡着不懂不安装,手动去对应的目录底下安装一下 在执行一边。
在上诉第2步报错:
Starting installation... Please restart this script from an administrative PowerShell!
随后使用管理员开一个cmd,再来执行一次...
结果一直卡在 Successfully installed Python 2.7 (至少20分钟...)
然后继续搜索解决方案,发现白等了...
卡在Successfully installed Python 2.7
处理后,接到错误:
Could not install Visual Studio Build Tools. Please find more details in the log files, which can be found at C:\Users\Administrator\.windows-build-tools
但这个目录下没有vs的安装日志啊?!?!(随后怀疑是之前报错时,我去那个目录找到文件,手动点击过安装,可能导致它自动安装不了了)
于是继续找解决方案Error: Could not find any Visual Studio installation to use
于是再次继续手动安装(不敢卸载vs,windows产品和它系统有紧耦合关系,有之前卸载后再也无法安装的可怕经历)
安装完成后,继续安装node-sass:
# 先卸载之前安装的,不然会报错 npm uninstall node-sass npm install node-sass
安装成功!
后续坑:
编译项目后,又收到报错:
Uncaught Error: Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/sass-loader/dist/cjs.js): Error: Node Sass version 8.0.0 is incompatible with ^4.0.0. at getSassImplementation (:8080/E:\git_coding\mall_recharge_uni\node_modules\@dcloudio\vue-cli-plugin-uni\packages\sass-loader\dist\getSassImplementation.js:46:13) at Object.loader (:8080/E:\git_coding\mall_recharge_uni\node_modules\@dcloudio\vue-cli-plugin-uni\packages\sass-loader\dist\index.js:42:61) at Object.yEaF (index.js:1685:7) at __webpack_require__ (index.js:854:30) at fn (index.js:151:20) at Object.GSuk (index.js:1086:15) at __webpack_require__ (index.js:854:30) at fn (index.js:151:20) at Module.XAuw (index.js:1167:940) at __webpack_require__ (index.js:854:30) at fn (index.js:151:20) at eval (null:1:1)
说明node版本和node-sass版本不兼容...
查找自己的node版本对应的node-sass版本,查找地址:https://www.npmjs.com/package/node-sass
自己本机是node14.13.1,对应node-sass版本为:4.14+,于是执行:
npm uninstall node-sass npm install node-sass@4.14
该问题解决!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
2012-11-30 CSS架构目标:预测、重用、扩展、维护