首页 > 解决方案 > 错误:合并到主分支后缺少绑定“binding.node”

问题描述

我尝试在 GitLab 的一个分支中配置 CI/CD 中的自动代码覆盖,并且管道在分支内完美通过,但是当管理员将更改合并到主分支时,管道由于缺少绑定而失败。

我曾经gitlab-ci.yml在其中配置我的工作。我没有任何使用管道的经验,所以这对我来说几乎是一个反复试验的任务。

最后,我得到了对我有用的配置,它没有破坏任何东西,并根据需要生成了覆盖范围。但是,由于它在成功构建之前显示没有空间错误,因此我不得不强制清除缓存以使作业正常运行。在我的分支中,管道没有任何错误地通过,我通过重新运行它多次进行了仔细检查。但是一旦管理员合并了分支,它突然开始产生以下错误:

ERROR in Module build failed: Error: Missing binding /builds/internal/employee_portal/node_modules/node-sass/vendor/linux-x64-64/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 10.x

Found bindings for the following environments:
  - Linux 64-bit with Node.js 11.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.
    at module.exports (/builds/internal/employee_portal/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/builds/internal/employee_portal/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.sassLoader (/builds/internal/employee_portal/node_modules/sass-loader/lib/loader.js:46:72)
ERROR in ./src/styles.scss
Module build failed: ModuleBuildError: Module build failed: Error: Missing binding /builds/internal/employee_portal/node_modules/node-sass/vendor/linux-x64-64/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 10.x

Found bindings for the following environments:
  - Linux 64-bit with Node.js 11.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.
    at module.exports (/builds/internal/employee_portal/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/builds/internal/employee_portal/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.sassLoader (/builds/internal/employee_portal/node_modules/sass-loader/lib/loader.js:46:72)
    at runLoaders (/builds/internal/employee_portal/node_modules/webpack/lib/NormalModule.js:244:20)
    at /builds/internal/employee_portal/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /builds/internal/employee_portal/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at runSyncOrAsync (/builds/internal/employee_portal/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/builds/internal/employee_portal/node_modules/loader-runner/lib/LoaderRunner.js:229:2)
    at Array.<anonymous> (/builds/internal/employee_portal/node_modules/loader-runner/lib/LoaderRunner.js:202:4)
    at Storage.finished (/builds/internal/employee_portal/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:16)
    at provider (/builds/internal/employee_portal/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:79:9)
    at /builds/internal/employee_portal/node_modules/graceful-fs/graceful-fs.js:90:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
ERROR: Job failed: exit code 1 

旁注:我正在处理的分支已从主分支中签出,其他分支中没有包含任何更改。

我想知道:

我看过这个链接,但我很好奇为什么这个错误在合并之前从未发生过,即使它发生了,为什么它给我一个错误,因为我安装了更新版本。

这是我的gitlab-ci.yml文件:

image: trion/ng-cli-karma

cache:
  paths:
  - node_modules/

build:
  stage: build
  script:
   - npm cache clear --force
   - npm i @angular/cli
   - npm install
   - npm run generate-docs
   - ./node_modules/.bin/ng build --prod --base-href . --output-path www/
  artifacts:
    paths:
      -  www/
      -  documentation/
  variables:
    DOCKER_DRIVER: overlay

test:
  stage: test
  script:
    - ./node_modules/.bin/ng test --code-coverage=true
  artifacts:
    paths:
      - coverage/
  coverage: '/(\d*.?\d+)%/'

pages:
  stage: deploy
  dependencies:
    - build
    - test
  script:
    - ls
    - mv documentation www/
    - mv coverage/ www/
    - mv www/ public
    - ls public/
  artifacts:
    paths:
      - public
    expire_in: 30 days

标签: dockercontinuous-integrationgitlabpipelinecontinuous-deployment

解决方案


我遇到了同样的问题,npm rebuild node-sass命令对我不起作用。原因是 npm 缓存。如果您清除缓存,问题将得到解决。

后续步骤:

  • 移除节点模块rm -rf node_modules/
  • 删除缓存npm cache clean --force
  • 验证缓存已删除npm cache verify
  • npm install

推荐阅读