node.js - 为什么 mkdir <path> 在 Windows 中运行 npm 时失败?

标签 node.js npm cygwin package.json

我在 Windows 上使用 Cygwin bash。当我运行 mkdir -p dist/ts 时,它工作正常。但是,当将相同的内容添加到 package.json 中的脚本时,例如

  "scripts": {
    "test1": "mkdir -p dist/ts "
  }

npm 返回以下错误:

The syntax of the command is incorrect.

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mmauricepinto\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "test1"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! angular2-google-maps@0.16.0 test1: `mkdir -p dist/ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-google-maps@0.16.0 test1 script 'mkdir -p dist/ts'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-google-maps package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     mkdir -p dist/ts
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2-google-maps
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular2-google-maps
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\cygwin\home\mmauricepinto\Startup\angular2-google-maps\npm-debug.log

最佳答案

这是 Windows 中的文件系统,在使用 mkdir 时应使用反斜杠。查看本文最后一段:https://www.windows-commandline.com/create-directory-command-line

使用这个:

  "scripts": {
    "test1": "mkdir -p dist\\ts"
  }

您需要使用两个反斜杠 \\ 因为在这种情况下它被解释为转义序列。

关于node.js - 为什么 mkdir <path> 在 Windows 中运行 npm 时失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41236078/

相关文章:

node.js - 安装 NPM mongoose 的问题

jenkins - 尝试从 Jenkins 随机连接到 Cygwin sshd 不起作用(无法将 ident 字符串写入 [clientIP]

Git 将相同的文件显示为已更改

c - 将 cmake 与共享(动态)库结合使用

mysql - 如何在与sequ​​elize Node 的关系上使用having子句

css - 具有多个入口点的 node-sass 脚本

node.js - 如何在 Typescript 项目中使用来自 Node 16 的计时器/ promise ?

javascript - 如何在 JavaScript 中设置函数执行顺序以使用回调函数?

node.js - 路径参数,在 aws lambda 中使用授权器时正文为 null

node.js - 在 Docker GitHub 操作中缓存 npm 包