先上報錯
關鍵行:
- Failed to compile. - 字面意思,編譯失敗,原因一般都在下面的白字報錯
- Module build failed (from ./node-modules/_sass-loader@7.3.1@sass-loader/dist/cjs.js): - 模塊構建失敗,注意后面的冒號,說明構建失敗的原因在下一行開始的若干行
- Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93) - node-sass 現在不支持當前生產環境:64位的Windows運行系統
- For more information on which environments are supported please see: https://github.com/sass/node-sass/releases/tag/v4.14.1 - node-sass 現在不支持當前生產環境
提取關鍵信息 Node Sass 現在不支持,具體為什么不支持,可能是電腦環境原因,也可能是 node-sass 版本與 sass-loader 不兼容,這也將我帶入了誤區。
錯誤操作示范
- 檢查 node-sass 與 sass-loader 版本
檢查 package.json 與 package-lock.json 的中的依賴版本,發現 package-lock.json 中的 sass-loader(7.3.1) ,而 package.json 中是 7.1.0 。
- 卸載重裝不同版本依賴
// 在 git / 命令行窗口 中運行代碼
// 卸載依賴包
npm uninstall sass-loader
// 完成后重新安裝依賴
npm install sass-loader@7.1.0
npm run 項目報錯依舊,只是報錯中的 sass-loader@7.3.1 變成了 sass-loader@7.1.0 (忘記截圖用上面的圖片p了一下,別介意)
- 卸載重裝 node-sass
有可能是因為圖速度使用 cnpm install 導致的,於是重裝依賴:
// 在 git / 命令行窗口 中運行代碼
// 卸載依賴包
npm uninstall node-sass
// 完成后重新安裝依賴
npm install node-sass
報錯依舊。
正確解決示范
下午 github 終於能打開了,這很關鍵:sass/node-sass
圖中關鍵信息:
- 當前 node-sass 版本:v4.14.1
- 該版本在 Windows 環境中支持 Node v0.10 - 14
- 僅支持64位操作系統
卸載本機Node並去官網查找對應的舊版本下載:Node官網
我裝了v14版本下的 Node 環境后 重新 npm run 項目,仍然報錯,但問題已經解決了,按提示進行操作就可以解決:
命令行中運行:
// rebuild node-sass
npm rebuild node-sass
完成后再跑項目!
仍然報錯,不要慌,刪除項目的 node_modules 文件夾, 重新運行 npm install
完成后再再再跑項目!
搞定!