Node 版本升级后 vue2 项目启动错误 (node-sass 与 sass-loader)
前言
开始使用低于 vue-cli3
创建的项目,在更新node
到 12.x
后,项目运行不起来了
问题描述
node 版本升级后旧的 vue 项目启动报错
- 错误类型1
node Sass could not find a binding for your current environment: Windows 64-bit with node.js 12.x
Found bindings for the following environments:
– Windows 64-bit with node.js 8.x
– Windows 64-bit with node.js 12.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
尝试执行命令 npm rebuild node-sass
,,提示安装 Python
环境
Error: Can’t find Python executable “python”, you can set the PYTHON env variable.
- 错误类型2
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.12.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.12.0 postinstall 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! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2022-06-15T13_59_40_556Z-debug.log
内容分析
通过错误信息提示以及网络查找,很容易就发现产生的原因:高版本的 NodeJS 对 node-sass 不是很友好(兼容问题)
下面是 node
与 sass-node
的版本对照
NodeJS | Supported node-sass version | Node Module |
---|---|---|
Node 17 | 7.0+ | 102 |
Node 16 | 6.0+ | 93 |
Node 15 | 5.0+, <7.0 | 88 |
Node 14 | 4.14+ | 83 |
Node 13 | 4.13+, <5.0 | 79 |
Node 12 | 4.12+ | 72 |
Node 11 | 4.10+, <5.0 | 67 |
Node 10 | 4.9+, <6.0 | 64 |
Node 8 | 4.5.3+, <5.0 | 57 |
Node <8 | <5.0 | <57 |
解决方法
重新安装对应兼容版本的 node-sass
即可,注意别忘了 sass-loader
npm install node-sass@6.0.1 sass-loader@10.2.0
结尾
本期的内容就到这里,路过的小伙伴记得支持一下哦!