【问题标题】:How can I run an npm script with a file path in windows?如何在 Windows 中运行带有文件路径的 npm 脚本?
【发布时间】:2021-03-17 00:52:08
【问题描述】:

我正在使用 Windows 机器开发一个项目,并且我有一些这样的 npm 脚本:

"start" : "./foo/bar"

当我尝试运行 npm run start 时出现此错误:

.\foo\bar is not recognized as an internal or external command,
operable program or batch file.

我注意到正斜杠已被翻转为 Windows 的反斜杠,但如果我自己运行此命令,bash 终端会将它们作为“转义”中断并返回:

bash: .foobar: command not found

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

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

【问题讨论】:

    标签: npm terminal npm-scripts


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-22
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 2019-10-14
      • 2017-12-11
      • 2014-06-08
      相关资源
      最近更新 更多