【问题标题】:"No such file or directory" when running command from NPM script从 NPM 脚本运行命令时“没有这样的文件或目录”
【发布时间】:2018-12-07 14:26:30
【问题描述】:

我想在我的 NPM 脚本中使用一个简单的命令。 命令是:

cat ./path/**/*.css > ./other/path/plugins.css

如果我在终端中运行它,它就可以工作。 但是,如果我将它放在 NPM 脚本中,如下所示:

"scripts" {
     "cat": "cat ./path/**/*.css > ./other/path/plugins.css"
}

我会得到没有这样的文件或目录。

知道可能是什么原因吗?

谢谢!

【问题讨论】:

    标签: npm-scripts


    【解决方案1】:

    它不起作用的原因是因为 cat 接受文件名作为参数,并且星号 (glob) 被您的 shell(很可能是 bash)转换为文件名。

    它不适用于 npm 脚本的原因是它没有在支持您想要使用的功能的 shell 中运行(glob 扩展、stdout 重定向到文件)。

    要解决它,只需在 bash 实例中运行它:

    "scripts" {
         "cat": "bash -c 'cat ./path/**/*.css > ./other/path/plugins.css'"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-08
      • 2018-03-24
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-10
      • 2015-02-20
      相关资源
      最近更新 更多