【问题标题】:How to fix 'Node Sass could not find a binding in your current env.' when running npm run build如何修复“Node Sass 在当前环境中找不到绑定”。运行 npm run build 时
【发布时间】:2019-08-29 14:11:51
【问题描述】:

我正在运行sudo npm run build,它说它找不到 sass 的绑定。我目前只安装了一个版本的 npm,它是 11.13.0

我试过了 npm install node-sass, npm rebuild node-sass, npm uninstall -save node-sass, npm install -save node-sass, npm cache clean,完全删除 node 和 node_modules 文件夹,但仍然出现相同的错误。然而,我确实安装了 8.0.0 版,但我使用 nvm 删除了它

ERROR in ./src/main/webapp/styles/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/main/webapp/styles/styles.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Missing binding /home/dev/IdeaProjects/web-project/node_modules/node-sass/vendor/linux-x64-57/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 8.x

Found bindings for the following environments:
  - Linux 64-bit with Node.js 11.x

如果您需要任何其他信息,请告诉我。

【问题讨论】:

  • 我有同样的错误,因为我使用的节点包不支持角度项目中的节点 sass 版本。我的建议你需要为 node js 安装 LTS 版本
  • npm 重建 node-sass?

标签: angular npm node-sass


【解决方案1】:

解决我同样问题的唯一方法是删除所有 node_modules 并重新安装它们,并且在 React 中一切正常。

【讨论】:

    【解决方案2】:

    这是由于项目中使用的节点版本与您全局安装的节点版本不匹配所致。

    1. 查看项目的 package.json 中指示的节点版本
    2. 将版本更改为所需的节点版本
    3. 通过在项目目录中执行 npm clean-install 清除项目的 node_modules 文件夹
    4. 发出npm install 重新安装所有软件包
    5. 使用:node -v 来确定您活动的节点版本。如果输出的版本与您在项目中设置的版本匹配,您的npm run build 命令将起作用。如果它们不匹配,则必须安装匹配版本的节点,或者如果您使用的是 nvm,请使用:nvm use <version> 激活匹配版本。

    【讨论】:

      【解决方案3】:

      试试命令:sudo npm install --save-dev --unsafe-perm node-sass

      对我有用

      【讨论】:

      • 这也是快速修复
      • 对我来说,当 package.json 中明确设置的节点版本为 10.xy 而安装的节点版本为 12.xy 时,它不起作用,所以不得不使用金曼的答案
      • 使用yarn怎么办?
      猜你喜欢
      • 2016-10-25
      • 2020-08-01
      • 2019-10-12
      • 2023-02-15
      • 1970-01-01
      • 2021-04-06
      • 2017-04-15
      • 1970-01-01
      • 2022-07-19
      相关资源
      最近更新 更多