如何解决Yarn 不能运行任何脚本
当我运行 yarn start
或任何其他以下脚本时:
"scripts": {
"start": "webpack-dev-server --config scripts/webpack.dev.js","clean": "rimraf build","build": "yarn run clean && yarn run compile","compile": "webpack --config scripts/webpack.prod.js","compile-for-test": "webpack --config scripts/webpack.test.prod.js","build-for-test": "yarn run clean && yarn run compile-for-test","test": "jest -c scripts/jest.config.js --testPathIgnorePatterns=\"services/contract-tests\"","test-ci": "node scripts/test-shell-commands.js unitTestCI","test-contract": "node scripts/test-shell-commands.js testLocal","test-contract-ci": "node scripts/test-shell-commands.js testCI","coverage": "node scripts/test-shell-commands.js unitTestCoverage","lint": "./node_modules/.bin/eslint --max-warnings=0 \"src/**\"","start-backend": "bash -l ./scripts/start-backend-container.sh","stop-backend": "bash -l ./scripts/stop-backend-container.sh","start-stub": "bash -l ./scripts/start-backend-stub-container.sh","stop-stub": "bash -l ./scripts/stop-backend-stub-container.sh","prettier": "prettier --write **/*{ts,tsx}"
},
我收到以下错误:
# yarn start
$ webpack-dev-server --config scripts/webpack.dev.js
error Couldn't find the binary webpack-dev-server --config scripts/webpack.dev.js
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
# yarn test
$ jest -c scripts/jest.config.js --testPathIgnorePatterns="services/contract-tests"
error Couldn't find the binary jest -c scripts/jest.config.js --testPathIgnorePatterns="services/contract-tests"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
这适用于所有脚本(不特定于 webpack 等)。但是,当我使用它 npm run start
时,它可以工作。 yarn add
或 yarn
命令也可以单独使用。只是我无法使用 yarn
运行任何脚本。
有没有人遇到过这种情况?
我的纱线版本是:1.22.10
我已经卸载并安装了几次,但问题仍然存在。操作系统:Windows
解决方法
这可能是因为 Yarn 使用节点的 child_process.spawn
,所以在将 bash 指定为 shell 时节点试图在 Windows 上生成命令的问题。
.yarnrc
中指定的 shell 脚本,将该 shell 作为 shell 选项传递给 spawn,并且当指定了一个 shell 并且 process.platform
评估为 win32
时,['/d','/s','/c'
将被添加到参数中(请参阅下面的 spawn()
来源)。
if (options.shell) {
const command = [file].concat(args).join(' ');
if (process.platform === 'win32') {
if (typeof options.shell === 'string')
file = options.shell;
else
file = process.env.comspec || 'cmd.exe';
args = ['/d','/c',`"${command}"`];
options.windowsVerbatimArguments = true;
请通过 yarn config get script-shell
检查您的纱线配置以验证 bash-path 的设置。
请参阅 child_process.spawn 了解更多信息..
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。