Node.js升级为8.x:Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x
最近把node从6.x升级到8.x后,旧项目编译scss文件时报错:
ERROR in ./src/app/note/account/user.component.scss
Module build failed: Error: Missing binding D:\webstormProjects\my-project\node_modules\node-sass\vendor\win32-x64-57\binding.node
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:
- Windows 64-bit with Node.js 6.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
at module.exports (D:\webstormProjects\mj-project\node_modules\node-sass\lib\binding.js:15:13)
at Object.<anonymous> (D:\webstormProjects\mj-project\node_modules\node-sass\lib\index.js:14:35)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\webstormProjects\mj-project\node_modules\sass-loader\lib\loader.js:3:14)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
这里提示原来项目绑定的是Windows 64-bit with Node.js 6.x。
方案一
在错误提示里有给出了方案,重新构建node-sass,命令如下:
npm rebuild node-sass --force
方案二
尝试了方案一(在网上找资料方案一都可以成功),但我执行方案一的命令包gyp Error,
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
....
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
实在不想解决为什么会报gyp ERR。
尝试卸载node-sass,然后重新安装node-sass。
npm uninstall node-sass
npm install node-sass
编译项目成功!