【问题标题】:Yarn cannot execute source commandYarn 无法执行 source 命令
【发布时间】:2021-03-09 05:13:31
【问题描述】:

我想在运行 Node JS 应用程序之前运行 NVM 命令。但是当我想执行source命令时,出现如下错误:

package.json 文件内:

{
  "scripts": {
    "prestart": "source $NVM_DIR/nvm.sh; nvm use 14.15.1"
  },
}

运行yarn run prestart命令后的输出:

yarn run v1.22.5
$ source $NVM_DIR/nvm.sh; nvm use 14.15.1
/bin/sh: 1: source: not found
/bin/sh: 1: nvm: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我该怎么办?尽管 sourcenvm 命令在 Yarn 之外运行良好。

【问题讨论】:

    标签: node.js linux yarnpkg package.json nvm


    【解决方案1】:

    也许您需要使用 \bin\bash 而不是 \bin\sh 来运行这些命令。

    检查此答案以更改纱线的默认外壳。

    Specify which shell Yarn uses for running scripts

    【讨论】:

    • 你能举个例子吗?我访问过你提供的链接,但还是不明白。
    • 通过发出 yarn config set script-shell /bin/bash 来更改 yarn 运行命令的默认 shell。恢复问题yarn config delete script-shell。也许 /bin/sh 无权访问 source 命令。所以试试 /bin/bash
    猜你喜欢
    • 2012-02-10
    • 2012-05-03
    • 2020-06-19
    • 2016-08-20
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    相关资源
    最近更新 更多