问题2更好的解决方案是这个
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x
Found bindings for the following Environments: Linux 64-bit with Node.js 12.x
以下是sass-loader的官方文档
By default the loader resolve the implementation based on your dependencies. Just add required implementation to package.json
(sass
or node-sass
package) and install dependencies.
Example where the sass-loader
loader uses the sass
(dart-sass
) implementation:
package.json
{
"devDependencies": {
"sass-loader": "^7.2.0",
"sass": "^1.22.10"
}
}
Example where the sass-loader
loader uses the node-sass
implementation:
package.json
{
"devDependencies": {
"sass-loader": "^7.2.0",
"node-sass": "^5.0.0"
}
}
也就是说,可以直接使用
sass
而不用node-sass
。
所以直接删除掉node-sass,然后安装sass吧
npm install sass sass-loader -D
-
项目中引入SCSS
$ npm i sass-loader@10.x node-sass -D
因为Vue环境用的是Vue@2.x ,如果直接安装sass-loader会安装11.x,该版本与Vue2.x不适配,可以装10.x
node-sass自动安装,我本地是5.0.0
-S 是 --save :安装在packages.json的dependencies下面 -D 是 --save-dev :安装在packages.json的devDependencies下面
-
安装好node-sass和sass-loader以后,重新跑项目,报以下错误
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x
Found bindings for the following Environments: Linux 64-bit with Node.js 12.x
node -v查看本地的node 版本就是12.x,但是sass-loader需要的是8.x
如果本地没有
- 官网找到对应的版本,下载安装。
$ npm rebuild sass-loader
- 重新运行项目