我在使用Facebook的JavaScript软件包管理器run
提供的命令时遇到了麻烦yarn
。
当前在我的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
。
我发现了一个我认为与之相关的问题: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 ."
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句