bash npm postinstall 因多个命令而失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18621489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:27:44  来源:igfitidea点击:

npm postinstall fails with multiple commands

node.jsbashcommand-line-interfacenpmpost-install

提问by kaiser

Inside my composer.json, there's a postinstallhook setup like the following:

在 my 中composer.json,有一个postinstall钩子设置,如下所示:

"scripts" : {
    "dist" :        "node dist; node_modules/.bin/doccoh src/package.js",
    "postinstall" : "node_modules/.bin/grunt setup || true; node_modules/.bin/bower install",
    "start" :       "node server.js"
}

Whenever I run it (on Win from Git/Gnu Bash CLI), I end with

每当我运行它(在来自 Git/Gnu Bash CLI 的 Win 上),我以

command not found. either the command was written wrong or couldn't be found

command not found. either the command was written wrong or couldn't be found

Rough translation from German CLI error.

来自德语 CLI 错误的粗略翻译。

I tried splitting it into multiple ;/semicolon separated parts and first cdinto that directory, but it simply ends up with the same error message. Replacing the whole postinstallcommand set with a simple lsdoes work. So I guessthe problem might be the semicolon separation or a wrong usage of commands. But overall I got no idea what's wrong.

我尝试将其拆分为多个;/ 分号分隔的部分,然后首先cd拆分到该目录中,但它最终只是以相同的错误消息结束。postinstall用简单的命令替换整个命令集ls确实有效。所以我问题可能是分号分隔或命令的错误用法。但总的来说,我不知道出了什么问题。

Note: I got grunt-cliversion 0.1.9 and gruntversion 0.4.1 installed globally.

注意:我在全局安装了grunt-cli0.1.9grunt版和0.4.1 版。

回答by Tucker Connelly

I'm a bit late to answer, but if you're on Windows, multiple commands on a single line are executed with the use of &&

我回答有点晚了,但是如果您使用的是 Windows,则使用 && 执行单行上的多个命令

postinstall: "some command && some other -c"

回答by Doug

I ran into this looking for something and thought this may help other people. I have found it easier to move to postinstall.js files as things get a little complicated. This makes it easier to deal with moving forward.

我遇到了这个寻找一些东西,并认为这可能会帮助其他人。我发现移动到 postinstall.js 文件更容易,因为事情变得有点复杂。这使得更容易处理前进。