【发布时间】:2016-10-14 18:07:01
【问题描述】:
我在使用 Facebook 的 JavaScript 包管理器 yarn 提供的 run 命令时遇到问题。
目前在我的package.json 文件中,我的scripts 对象有以下内容。
"scripts": {
"lint": "./node_modules/.bin/eslint --ignore-pattern dist ."
}
当我运行以下命令时,它按预期工作,npm run lint。但是,当我从 yarn 和 yarn run lint 运行脚本时,我收到以下错误。
Petesta :: λ -> ~/Git/yarn yarn run lint
yarn run v0.15.1
$ "./node_modules/.bin/eslint --ignore-pattern dist ."
sh: ./node_modules/.bin/eslint --ignore-pattern dist .: No such file or directory
error Command failed with exit code 127.
info Visit http://yarnpkg.com/en/docs/cli/run for documentation about this command.
./node_modules/.bin 目录在我的$PATH 上,我确实注意到如果您有像date 或pwd 这样的可执行文件,那么yarn run some_script_on_date 将按预期工作。
实现此功能的一种方法是创建一个单独的 shell 文件,其中包含您尝试执行的命令。我们就叫它./scripts/lint.sh吧。
#!/bin/bash
./node_modules/.bin/eslint --ignore-pattern dist .
然后在文件chmod +x ./scripts/lint.sh上运行这个命令
现在在您的 scripts 对象中添加以下行。
"new_lint": "./scripts/lint.sh"
现在yarn run new_lint 将按预期运行。
我是否遗漏了什么,或者这是否需要在yarn 中调用脚本?我想像npm一样运行命令。
【问题讨论】:
标签: javascript yarnpkg