nodejs版本太高导致的导致的node-sass不兼容问题

看网上大多数文章都是建议降低nodejs版本!其实可以通过匹配对应的node-sass和sass-loader版本来解决兼容性问题。尽量使用新的版本!

问题一:Node Sass version 7.0.1 is incompatible with ^4.0.0.

可以通过升级 sass-loader 的版本解决。

问题二:TypeError: this.getOptions is not a function。

sass-loader 版本太高,可以通过降低版本解决。

===========>然后翻阅了 sass-loader 的 github [ https://github.com/webpack-contrib/sass-loader/releases/tag/v11.0.0 ]
发现 sass-loader@11.0.0 版本需要 webpack@5.0.0 ,而 @vue/cli@4.5.0 所用的是 webpack@4,所以需要将 sass-loader的版本降到11以下。(转自:[解决]TypeError: this.getOptions is not a function - 简书


===========>node-sass 和 node 的版本匹配关系通过github获取。(https://github.com/sass/node-sass

Node 177.0+102
Node 166.0+93
Node 155.0+, <7.088
Node 144.14+83
Node 134.13+, <5.079
Node 124.12+72
Node 114.10+, <5.067
Node 104.9+, <6.064
Node 84.5.3+, <5.057
Node <8<5.0<57

最后的版本组合:

node v16.13.1

"node-sass": "^6.0.1"

"sass-loader": "^10.2.0"

  • 7
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
【用于解决 failed Error: not found: python2 node-sass】 报错信息如下: ``` npm WARN prefer global node[email protected] should be installed with -g > node-sass@4.5.2 install E:\workspace_vscode\ww\node_modules\node-sass > node scripts/install.js Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5 .2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win3 2-x64-48_binding.node": connect ETIMEDOUT 54.231.72.83:443 Timed out whilst downloading the prebuilt binary Hint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234 or configure npm proxy via npm config set proxy http://example.com:8080 > node-sass@4.5.2 postinstall E:\workspace_vscode\ww\node_modules\node-sass > node scripts/build.js gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` failed Error: not found: python2 gyp verb `which` failed at getNotFoundError ``` 这个问题有两个解决方案 1. 按照提示需要 python2 环境,安装python2环境确实可以解决, 网上好多这种(管理员身份执行)。但是当你本来就有python环境时,环境变量不能自动替换,整起来就很麻烦。 ``` npm install --global --production windows-build-tools ``` 2. 第二种解决方案 ,看另一句报错,资源被墙。 ``` Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node": ``` 下载此资源即可。下载后需要设置变量路径,防止它再次去下载。 可以设置环境变量 直接右键我的电脑--》属性--》级系统设置--》环境变量--》添加 或者执行 ``` set SASS_BINARY_PATH=D:\nodejs\tools\node-sass\win32-x64-46_binding.node ``` 再次执行 npm install 成功

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值