cygwin/windows下的NPM脚本:命令的语法不正确

NPM script under cygwin/windows: the syntax of the command is incorrect

我在 Windows 7 机器上 运行ning Node 6.9.5 和 NPM 3.10.10。我的终端是 Cygwin 2.877.

如果我尝试 运行 在 Cygwin 中执行以下操作,它工作正常:

mkdir mydir/mysubdir;

但是,如果我将其放入 package.json 文件中,例如:

"scripts": {
 "test": "mkdir mydir/mysubdir"
},

和运行:

npm run test

它失败了:

The syntax of the command is incorrect.

谷歌搜索以上内容后,似乎是 Windows 命令提示符错误,而不是 Cygwin 错误。因此,似乎 NPM 正在尝试 运行 使用命令提示符而不是现有的 Cygwin 环境来编写脚本。

我该如何解决这个问题?或者更确切地说,我如何确保 NPM 运行s 脚本在终端环境中被调用?

脚本总是运行默认windowsshell,不是cygwin。

如果你想让它在 bash 中 运行 然后把它放在 package.json 中:

"scripts": {
    "test": "bash test.sh"
},

并将其放入 test.sh:

#!/bin/bash
mkdir mydir/mysubdir

或者,正如 csvan 在评论中指出的那样,您可以使用 Node 脚本代替 shell 脚本:

"scripts": {
    "test": "node test.js"
},

这种方法在 cross-platform 兼容性方面甚至更好。

另请参阅: