【问题标题】:NPM install is crashing with error "ERR! cb() never called!"NPM 安装因错误“ERR!cb() never call!”而崩溃
【发布时间】:2021-11-23 19:15:57
【问题描述】:

我们在云构建过程中定期看到构建失败并出现以下错误:

docker.io/library/node:14 npm 错误! cb() 从未调用过!

npm 错误!这是 npm 本身的错误。请报告此错误 在:npm 错误! https://npm.community

构建配置的步骤:

steps:
  - name: 'gcr.io/cloud-builders/git'
    id: 'fetch'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        # convert the shallow clone to regular one
        git fetch --unshallow --no-tags
    waitFor: ['-']

  - name: 'node:14'
    id: 'npm-install'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        npm ci --unsafe-perm
    env:
      - 'CYPRESS_INSTALL_BINARY=0'
      - 'CYPRESS_CACHE_FOLDER=/cypress_cache'
    waitFor: ['fetch']

有什么想法可以尝试或解决这个问题吗?

编辑:所有包都是从 npm 安装的。

【问题讨论】:

  • 什么托管 npm 注册表,从哪里安装包?
  • 这种情况只是偶尔发生吗?你的 npm 和 Node 版本兼容吗?这是旧的但可能有用:stackoverflow.com/questions/15393821/…
  • @MilanTenk 所有包都来自 npmjs。
  • @JavierA 它只是偶尔发生。是的 node / npm 版本是兼容的,因为这是官方 node:14 docker 容器
  • 难道没有公司代理或政策偶尔会阻止下载包吗?

标签: npm npm-install google-cloud-build


【解决方案1】:

正如@Milan Tenk 所建议的那样,一个好的方法是通过将命令包装在 bash 脚本中来在构建中实现重试逻辑。

Here 是一些关于如何将 yaml 文件修改为在 Cloud Build 中运行 bash 脚本的示例:

steps:
- name: 'bash'
  args: ['./retryPolicy.bash']

如果 bash 不是默认入口点:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args: ['tools/retryPolicy.sh','--foo']

here是bash中重试逻辑实现的一个例子:

#!/bin/bash
set -euo pipefail

function myFunction() {
    myCommand
    return $?
}

retry=0
maxRetries=5
retryInterval=15
until [ ${retry} -ge ${maxRetries} ]
do
    myFunction && break
    retry=$[${retry}+1]
    echo "Retrying [${retry}/${maxRetries}] in ${retryInterval}(s) "
    sleep ${retryInterval}
done

if [ ${retry} -ge ${maxRetries} ]; then
  echo "Failed after ${maxRetries} attempts!"
  exit 1
fi

如果这种方法对你有用,请告诉我。

【讨论】:

    【解决方案2】:

    请参阅 NPM CLI 维基: https://github.com/npm/cli/wiki/%22cb()-never-called%3F-Exit-handler-never-called%3F-I'm-having-the-same-problem!%22

    遗憾的是,从来没有一个直截了当的答案。

    但是,很多人似乎建议删除项目中的node_modules 文件夹并同时运行命令npm cache clean -force

    对我来说它不起作用 - 所以我从 PC 复制了一个 node_modules 文件夹,它可以运行 npm install 而不会出现错误。 这至少允许使用npm install 没有错误并再次构建项目。

    【讨论】:

      猜你喜欢
      • 2019-12-10
      • 2020-05-30
      • 2020-06-04
      • 1970-01-01
      • 2020-06-15
      • 2018-03-20
      • 2021-03-03
      • 2015-09-09
      • 2018-09-19
      相关资源
      最近更新 更多