命令未找到:如果使用 Yarn v3 (berry) 运行 package.json 脚本时

问题描述 投票:0回答:2

我将我们的项目 yarn 从 v1.22 升级到 v3.1.1。我们使用工作区,所以我有那个插件。一切似乎都很好;其他脚本可以工作,但是在尝试使用 shell 命令时出现此错误:

> yarn run start
command not found: if
command not found: then
command not found: fi

这是我们 package.json 中的脚本:

"scripts": {
    "build": "yarn run --top-level tsc",
    "lint": "yarn run --top-level eslint './src/**/*.{ts,js}'",
    "start": "if [[ $BLAH ]]; then yarn generateEnvFile; fi && yarn copyEnterpriseWsdl && node dist/index.js",
    "generateEnvFile": "node blah.js > .env",
    "copyEnterpriseWsdl": "cp blah blah"
  }
yarnpkg npm-scripts yarnpkg-v3
2个回答
1
投票

我最终得到了更多的解决方法,而不是弄清楚问题是什么:

"scripts": {
    // ...
    "start": "/bin/sh ./start-prod.sh"
  }

那个脚本有我真正需要运行的地方。 🤷u200d♂️


0
投票

如果你仍然想保持代码内联,你可以使用以下方法:

"scripts": {
    // ...
    "start": "/bin/sh -c 'if [[ $BLAH ]]; then yarn generateEnvFile; fi' && yarn copyEnterpriseWsdl && node dist/index.js"
  }
© www.soinside.com 2019 - 2024. All rights reserved.