node-sass和sass-loader安装报错

通常在安装node-sass和sass-loader的时候,会报各种各样的错,大多数安装不成功都是因为node的版本问题,由于node版本过高,导致与node-sass和sass-loader不兼容,导致的报错。

安装通常有如下问题:
问题一:
TypeError: this.getOptions is not a function
在这里插入图片描述
原因及解决办法:sass配置版本较高,不兼容当前的node,因此需要sass降低到稳定的版本
解决步骤:

1.需要先卸载原来的sass安装配置
npm uninstall --save sass-loader // 卸载
npm uninstall --save node-sass // 卸载

2.重装Sass,并指定版本。
npm i -D [email protected] // 安装
npm i [email protected] // 安装

如上述操作还不行,卸载依赖,并在package.json中找到node-sass,手动将改版本号,改为node-sass:“^4.14.1”,然后再npm install,即可。

大多数情况下可以将node版本降至12.14.0/12.14.1后,重新安装node-sass和sass-loader,故障解决

3.如果安装node-sass报错为:Python executable python2 in the PATH

npm install 报错 check python checking for Python executable python2 in the PATH
删除 node_modules 文件夹
在 Terminal 运行 npm install --global windows-build-tools --save
再安装 npm install node-sass --save
到这里,错误应该就已经解决了,收到了 gyp info ok 的提示!
如果遇到 Node Sass could not find a binding for your current environment,再运行 npm rebuild node-sass 就可以了

猜你喜欢

转载自blog.csdn.net/weixin_47818125/article/details/127342901