我有问题构建一个应用程序,因为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,这两者都没有解决问题。什么好主意吗?


当前回答

Mac:

- cmd + SHIFT + G ——/ usr /地方/ lib / node-sass -右击并重命名:应该仍然是相同的node-sass -然后执行NPM install node-sass -g

固定。

其他回答

我只是运行npm rebuild而不是npm rebuild node-sass,问题就消失了。但我不知道背后的魔力是什么。

node-sass节点模块使用依赖于节点版本的达尔文二进制文件。没有下载二进制文件或下载了错误的二进制文件时,会出现此问题。

[![节点sass错误][1]][1].

重新安装节点模块将下载node-sass的二进制文件:-

Mac用户:

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

Windows用户:

rmdir node_modules
npm cache clean --force
npm i
npm rebuild node-sass --force

但是对于某些用户,您需要检查您的节点版本与node-sass版本的兼容性。使用下面的表使其兼容,并再次运行以上命令来修复此问题。

这是node-sass的节点兼容性表

NodeJS | Supported node-sass version | Node Module
Node 17     7.0+                        102
Node 16     6.0+                        93
Node 15     5.0+                        88
Node 14     4.14+                       83
Node 13     4.13+, <5.0                 79
Node 12     4.12+                       72
Node 11     4.10+, <5.0                 67
Node 10     4.9+, <6.0                  64
Node 8      4.5.3+, <5.0                57
Node <8     <5.0                        <57

如果问题仍未解决,请检查node-sass支持的环境列表:—https://github.com/sass/node-sass/releases/

node-sass runs an install script to download the required binary. If there are no environment variables, .npmrc variables or process arguments set then the binary is determined by using the current process platform, architecture and Node ABI version. Therefore, if you run node install in one application and then try to run node-sass in an application with a different platform/architecture/ABI, the binary won't have been downloaded. The solution is to manually download the binary or to fix the binary version using an environment variable (SASS_BINARY_NAME) or a .npmrc variable (sass_binary_name)

你可以在node-sass\lib\extensions.js中的getBinaryPath函数中看到这个逻辑

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将下载容器操作系统的正确绑定。

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

我能解决的问题 NPM install -global -production windows-build-tools

NPM install——msvs_version=2015

" devDependencies ": { :“babel-core ^ 6.26.0”, :“babel-loader ^ 7.1.4”, :“babel-plugin-transform-decorators-legacy ^ 1.3.5”, :“babel-preset-env ^ 1.6.1”, :“babel-preset-react ^ 6.24.1”, :“babel-preset-stage-2 ^ 6.24.1”, :“css-loader ^ 0.28.11”, :“mini-css-extract-plugin ^ 0.4.0”, :“node-sass ^ 4.11.0”, :“sass-loader ^ 6.0.7”, 4.4.1“webpack”:“^”, :“webpack-cli 3.1.0”, :“webpack-dev-server ^ 3.1.1” }