npm - 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 使用 node 的child_process.spawn
.
中指定的 shell 脚本.yarnrc
将该 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', '/s', '/c', `"${command}"`];
options.windowsVerbatimArguments = true;
请检查您的纱线配置yarn config get script-shell
,以验证 bash-path 的设置。
有关更多信息,请参见child_process.spawn ..
推荐阅读
- linux - 我应该在 .bash_profile 中的哪里插入 PATH?
- android - 膨胀类 com.google.android.material.floatingactionbutton.FloatingActionButton 仪器测试时出错
- latex - 如何防止长方程跨越两列页面?
- http - 如何从 Power Automate“收到 HTTP 请求时”触发操作中获取文件名
- python - Python Re:经过测试的正则表达式模式不返回匹配项
- javascript - 如何使用 java-script 或 Jquery 对 HTML5 表上的重复单元格值进行行计数?
- optaplanner - 两个规划实体的建设问题
- python - Python - pyinstaller:读取脚本内的路径文件以在 pyinstaller 中使用
- sql - 如何在 Presto 中将小时数解析为人类可读的字符串?(时间小数)
- python - 如何在python函数中返回一个整数?