如何在windows中使用文件路径运行npm脚本



我正在用windows机器进行一个项目,我有一些npm脚本,如下所示:

"start" : "./foo/bar"

当我尝试运行npm run start时,我会收到以下错误:

.foobar is not recognized as an internal or external command,
operable program or batch file.

我注意到windows的正斜杠已经被翻转为反斜杠,但如果我自己运行这个命令,bash终端会以"转义"的形式中断它们并返回:

bash: .foobar: command not found

如果我在npm脚本中使用./foo/bar.\foo\bar,则文件在终端中运行正常,但如果我使用它们,则文件运行不正常。

我该怎么做才能让它在Windows中运行?此外,有没有一种方法可以将其编写为与Win/Mac/Linux兼容?

当您第一次使用普通斜杠执行cd时(npm/nodejs似乎可以根据操作系统解决此问题(,然后只需指定文件即可。

"scripts": {
"not-working": "scripts/another-folder/foo.cmd",
"working": "cd scripts/another-folder && foo.cmd"
},

最新更新