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
.
I found an issue which I believe is related: https://github.com/yarnpkg/yarn/pull/809.
yarn did not understand spaces in npm scripts. I guess this will be fixed in next release. I can reproduce the issue on my computer (using latest yarn: 0.15.1).
By the way, you do not have to include ./node_modules/.bin
in your npm scripts. Both npm and yarn will look inside that folder by default, as explained here: https://docs.npmjs.com/cli/run-script
So your script can be only: "lint": "eslint --ignore-pattern dist ."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With