【问题标题】:Yarn can't run any scriptYarn 无法运行任何脚本
【发布时间】:2021-01-29 11:32:21
【问题描述】:

当我运行 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 addyarn 命令单独也可以工作。只是我无法使用yarn 运行任何脚本。

有人遇到过这种情况吗?

我的纱线版本是:1.22.10 我已经卸载并安装了几次,但问题仍然存在。操作系统:Windows

【问题讨论】:

  • 您是否可能使用过不间断个空格?
  • 我仔细检查过,但事实并非如此。
  • 当您尝试运行script 时,yarn 似乎无法找到可执行依赖项。我建议删除node_modules 文件夹,运行yarn cache clean。之后运行yarn install 并尝试运行yarn start
  • 运行yarn config get script-shell的回报是多少?
  • @iLuvLogix 在你提出问题后我意识到它不是在寻找正确的路径。请回答问题,我会接受:)

标签: npm yarnpkg


【解决方案1】:

这可能是节点在将 bash 指定为 shell 时尝试在 Windows 上生成命令的问题,因为 Yarn 使用节点的 child_process.spawn

.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', '/s', '/c', `"${command}"`];
      options.windowsVerbatimArguments = true;

请通过yarn config get script-shell 检查您的纱线配置,以验证 bash-path 的设置。

更多信息请见child_process.spawn..

【讨论】:

    猜你喜欢
    • 2020-03-03
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2021-02-15
    • 2015-12-27
    相关资源
    最近更新 更多