纱线:在 gatsby 部署到 netlify 后找不到命令

yarn: command not found after gatsby deployment to netlify

我一直收到这个错误。

Executing user command: yarn build
/usr/local/bin/build: line 112: yarn: command not found

我从 Netlify - Manage build dependencies 得知 yarn 必须包含在我的 package.json 中。但是我在 package.json

中看到 yarn

我已经清理缓存并再次部署。我尝试添加 yarn 和 npm 版本作为构建环境,但它仍然不起作用。我还查看了 How to change your default package manager for your next project? 但没有找到具有以下结构的 json:

{
  "cli": {
    "packageManager": "yarn"
  }
}

FWIW 这在 本地 构建良好。只有在我推送到我的远程仓库并且 Netlify 正在构建之后才会出错。更奇怪的是,如果我使用 default 启动器,则不会发生此错误。

这有点违反直觉,但我需要做的就是将一个空的 yarn.lock 文件添加到根目录并将其推送到我的存储库。错误消息立即消失!

来自Netlify - Manage build dependencies

⚠️ yarn needs a yarn.lock

If any of your build scripts start with yarn, you must have a yarn.lock file.

Netlify's buildbot will not install Yarn without it.