在 yarn 中查找命令的间歇性失败(127)

Intermittent failure (127) to find command in yarn

我正在尝试在 gcloud 上构建一些东西,特别是使用 Yarn 和 Node 的网站。

这是我正在尝试的脚本 运行:

"build:langs": "printenv && ls -lah node_modules/.bin && BABEL_ENV=test babel-node scripts/translate.js",

通过

$ yarn run build:langs

输出 https://gist.github.com/haf/ebc623bfce5520432c136e44496b58fb — 这里有趣的部分(为便于阅读而格式化):

Step #2 - "js-build-langs": 
PATH=/workspace/src/site.com/node_modules/.bin
  :/usr/local/share/.config/yarn/link/node_modules/.bin
  :/workspace/src/
...
total 40K
Step #2 - "js-build-langs": drwxr-xr-x 2 root root 4.0K Jun 3 19:18 .
Step #2 - "js-build-langs": drwxr-xr-x 1194 root root 36K Jun 3 19:19 ..
Step #2 - "js-build-langs": lrwxrwxrwx 1 root root 20 Jun 3 19:18 JSONStream -> ../JSONStream/bin.js
Step #2 - "js-build-langs": lrwxrwxrwx 1 root root 19 Jun 3 19:18 _mocha -> ../mocha/bin/_mocha
...
Step #2 - "js-build-langs": lrwxrwxrwx 1 root root 30 Jun 3 19:18 babel-node -> ../babel-cli/bin/babel-node.js
...
Step #2 - "js-build-langs": /bin/sh: 1: babel-node: not found
Step #2 - "js-build-langs": error Command failed with exit code 127.
Step #2 - "js-build-langs": info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

一个容器构建器:

这还不是全部,因为在这场畸形秀中,几分钟前(现在:几小时):

cloudbuild 目标如下所示:

steps:
# JS from https://console.cloud.google.com/gcr/images/cloud-builders/GLOBAL/yarn?gcrImageListsize=50:
- name: gcr.io/cloud-builders/yarn:node-8.11.0
  waitFor: ["-"]
  id: js-install
  dir: src/site.com
  args: ["install"]

- name: gcr.io/cloud-builders/yarn:node-8.11.0
  waitFor: ["js-install"]
  id: js-build-prod
  dir: src/site.com
  args: ["run", "build:prod"]

- name: gcr.io/cloud-builders/yarn:node-8.11.0
  waitFor: ["js-build-prod"]
  id: js-build-langs
  dir: src/site.com
  args: ["run", "build:langs"]

和packages.json剪断:

  "devDependencies": {
    "@babel/core": "^7.0.0-beta.49",
    "@babel/node": "^7.0.0-beta.49",

总而言之,我很困惑。尽管 PATH 包含二进制 js 文件,但它为什么不工作,这是可执行的 non less?为什么能找到webpack却找不到babel-node?为什么我 运行 即使在完整的 git clean -fxd 之后也可以在本地使用它?为什么它有时会起作用而其他时候却不起作用?

我的直觉告诉我这是 GCB 中的某种竞争条件

当您 运行 在托管 Google Container Builder, the only data that gets shared across build steps is data in the shared /workspace directory (and configured volumes 上时,但您没有在您提供的代码段中使用任何内容。

我不是 npm 或 yarn 专家——但是您的任何软件包是否更改了它们在 package.json 配置中的 node_modules 位置?请注意,yarn install 采用 --modules-folder 选项,这可能会有帮助。

编辑 3:这对我们来说偶尔会出现,这是我们目前的想法。

当我们在 package.json 中将 yarn-commands 与 && 链接在一起时,会导致创建问题,例如node_modules/mocha/bin/mocha.js 或其他可执行js文件。

我们将 packages.json 中的每个命令都设为非链接并清除 node_modules。现在至少完成了一个构建。

谷歌搜索“找不到 127 命令”,'yarn' 没有给出任何提示。