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


当前回答

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

其他回答

卸载和安装sass包对于手动过程很有效,但对于自动部署/CI/CD,你需要更通用的方法。对我来说,适用于不同环境的Continuos部署是:

在部署前使用rimraf删除旧的node_modules rimraf node_modules 更新npm包中的sass包。Json &提交到源代码控制。

对于下一次部署,它将自动刷新所有环境的sass。

对我来说,当我运行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.js的更新并且全局使用node-sass时,就会发生这种情况。

因此,您应该全局卸载node-sass

npm uninstall -g node-sass

然后你必须再次全局安装它

npm install -g node-sass

我在本地运行Docker中的一个构建时,使用一个节点alpine映像,很长一段时间都有这个问题。我用下面的代码来创建基础层:

FROM node:19.4-alpine3.17 AS node_base
RUN apk update && \
    apk add python3 make && \
    rm -rf /var/cache/apk/*

它缺少了一个包:g++。把上面的改为下面的,对我来说很管用:

FROM node:19.4-alpine3.17 AS node_base
RUN apk update && \
    apk add python3 make g++ && \
    rm -rf /var/cache/apk/*

我相信这与带有M1芯片的macbook PRO的架构有关,在其他机器上我不会遇到这个错误,但我还没有测试过。

对我来说,是maven-war-plugin对文件应用了过滤器,损坏了woff文件。

<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
    <webResources>
        <resource>
            <directory>dist</directory>
            <filtering>true</filtering>
        </resource>
    </webResources>
</configuration>

真正删除<过滤> < /过滤>

或者如果你需要过滤,你可以这样做:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <directory>dist</directory>
                <excludes>
                    <exclude>assets/**/*</exclude>
                </excludes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>dist</directory>
                <includes>
                    <include>assets/**/*</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>