問題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環(huán)境用的是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
如果本地沒有
- 官網(wǎng)找到對應的版本,下載安裝。
$ npm rebuild sass-loader
- 重新運行項目