6

I'm having trouble using the run command provided by yarn, Facebook's package manager for JavaScript.

Currently in my package.json file I have the following for my scripts object.

"scripts": {
  "lint": "./node_modules/.bin/eslint --ignore-pattern dist ."
}

When I run the following command, it works as expected, npm run lint. However, when I run the script from yarn with yarn run lint I receive the following error.

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.

The ./node_modules/.bin directory is on my $PATH and I did notice that if you have an executable like date or pwd then yarn run some_script_on_date will work as expected.

One way to get this to work is to create a separate shell file containing the command you're trying to execute. Let's call it ./scripts/lint.sh.

#!/bin/bash

./node_modules/.bin/eslint --ignore-pattern dist .

And then run this command on the file chmod +x ./scripts/lint.sh

Now in your scripts object add the following line.

"new_lint": "./scripts/lint.sh"

And now yarn run new_lint will run as expected.

Am I missing something or is this how calling scripts in yarn needs to be done? I would like for to run the command like with npm.

4

1 回答 1

3

我发现了一个我认为相关的问题:https ://github.com/yarnpkg/yarn/pull/809 。

yarn 不理解 npm 脚本中的空格。我想这将在下一个版本中修复。我可以在我的电脑上重现这个问题(使用最新的纱线:0.15.1)。

顺便说一句,您不必包含./node_modules/.bin在您的 npm 脚本中。默认情况下,npm 和 yarn 都会在该文件夹内查看,如下所述:https ://docs.npmjs.com/cli/run-script

所以你的脚本只能是:"lint": "eslint --ignore-pattern dist ."

于 2016-10-14T19:01:59.060 回答