我有问题构建一个应用程序,因为node-sass不断失败的错误。

binding /Users/warren/Sites/random-docs/my-cms/node_modules/node-sass/vendor/darwin-x64-11/binding.node出错 Node Sass无法找到当前环境的绑定:OS X 64位的Node 0.10.x

我试过跑步

npm rebuild node-sass

二进制很好;退出。

当运行node -v时,我得到v6.2.2

这与sass错误说的“Node 0.10.x”不同。我不明白为什么它会得到错误的版本。我也尝试删除node_modules文件夹并运行npm update或npm install,这两者都没有解决问题。什么好主意吗?


当前回答

如果你的终端/命令提示符显示:

Node Sass could not find a binding 
for your current environment: 
OS X 64-bit with Node 0.10.x

并且您已经尝试了以下命令,例如:

npm cache clean --force 
rm -rf node_modules 
npm install 
npm rebuild node-sass

仍然没有工作…

只需在终端中手动运行:node node_modules/node-sass/scripts/install.js

现在运行NPM start或yarn start

其他回答

对我来说,当我运行npm安装时,它审计了已安装的包,并显示“发现1个高严重漏洞”,并通过运行

npm audit fix

成功了。如果能帮助到别人就发布。

更新:共享错误日志:

ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/styles.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Missing binding ..\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 10.x

This usually happens because your environment has changed since running `npm install`.
....

它确实要求我这么做

Run `npm rebuild node-sass` to download the binding for your current environment.

我也遇到过类似的问题,原因是我的机器上安装了两个版本的Node:一个是“全局”版本,另一个是项目级别的版本。 只有在Gulp构建在Node.js 4下运行时,Sass才能正确构建。x版本,因此请确保升级了您正在使用的Node版本。

PS:如果你完全删除项目中的node_modules文件夹并从头开始重新构建,npm将下载当前系统和节点版本的正确依赖项。

我在Windows环境中遇到了同样的问题,收到以下错误:

C:\Development{ProjectName}\node_modules\node-sass\vendor\win32-ia32-47\binding.node Node Sass无法找到当前环境的绑定:Windows 32位,带有Node.js 5.x 为以下环境找到绑定: —Windows 64位,Node.js 6.x

这里其他答案中列出的npm命令(npm install, npm rebuild node-sass等)都不起作用。

相反,我必须下载缺失的绑定,并将其放在适当的目标文件夹中。

可以在git上找到绑定。将该文件与错误消息中/node_modules/node-sass/vendor/后面标识的文件夹名匹配(在您的示例中是'darwin-x64-11',因此您需要darwin-x64-11_binding. xml文件)。节点文件)。

在项目中创建缺少的文件夹(/node_modules/node-sass/vendor/darwin-x64-11),将.node文件复制到新目录,并将其重命名为binding.node。

Node-sass发布URL: https://github.com/sass/node-sass/releases

在“node_modules/node-sass/vendor/linux-x64-46/”目录下新建一个目录。 从https://github.com/sass/node-sass/releases下载文件 (linux-x64-59_binding.node)。 将其粘贴到node_modules/node-sass/vendor/linux-x64-46/重命名为binding.node

NPM重建node-sass——force

或者,如果你在容器中使用node-sass:

Docker exec <container-id> NPM rebuild node-sass——force

当node-sass没有当前操作系统的正确绑定时,会发生此错误。

如果你使用Docker,当你将node_modules直接添加到Dockerfile中的容器文件系统(或使用Docker卷挂载它们)时,通常会发生这种错误。

容器体系结构可能与当前的操作系统不同。例如,我在macOS上安装node-sass,但我的容器运行Ubuntu。

如果强制node-sass从容器内部重新构建,node-sass将下载容器操作系统的正确绑定。

查看我的复制案例了解更多。