繁体   English   中英

无法在package.json中的脚本对象上运行“yarn run”

[英]Trouble running “yarn run” on scripts object in package.json

我使用的是有问题run提供命令yarn ,Facebook的JavaScript的包管理器。

目前在我的package.json文件中,我的scripts对象有以下内容。

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

当我运行以下命令时,它按预期工作, npm run lint 但是,当我使用yarn run lintyarn运行脚本时,我收到以下错误。

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 ,我注意到如果你有一个像datepwd这样的可执行文件,那么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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM