无法在 Windows 的 NPM 脚本中使用 mkdir
Can't use mkdir in NPM script from Windows
我正在尝试创建一个如下所示的脚本:
{
"scripts":
"setup": "mkdir -p ./my-dir"
}
它失败了,至少在 Windows 上失败了,即使我 运行 它来自 Git Bash 提示。即使只尝试 mkdir ./my-dir
也行不通。我想不出它应该失败的任何原因。
它给出的错误是"syntax incorrect"错误:
> my-app@0.0.1 stage C:\my-app
> mkdir ./my-dir
The syntax of the command is incorrect.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "stage"
npm ERR! node v6.4.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! my-app@0.0.1 stage: `mkdir ./my-dir`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.0.1 stage script 'mkdir ./my-dir'.
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 my-app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mkdir ./my-dir
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs my-app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls my-app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\my-app\npm-debug.log
如果这行不通,是否有一种跨平台友好的方法来初始化一个空目录?
这个模块可能会解决你的问题:
https://www.npmjs.com/package/mkdirp
Npm 使用 windows mkdir 命令,而不是 linux。使用
"setup": "mkdir .\my-dir"
使用反斜杠。
你也可以安装cygwin和运行:
/cygwin64/bin/mkdir -p mydir
您可以使用 npx plus mkdirp 相对轻量级、便携的解决方案,无需全局安装
将此添加到 package.json
:
"scripts": {
"create-dir": "npx mkdirp _site/assets",
}
然后像这样使用:
$ npm run create-dir
我正在尝试创建一个如下所示的脚本:
{
"scripts":
"setup": "mkdir -p ./my-dir"
}
它失败了,至少在 Windows 上失败了,即使我 运行 它来自 Git Bash 提示。即使只尝试 mkdir ./my-dir
也行不通。我想不出它应该失败的任何原因。
它给出的错误是"syntax incorrect"错误:
> my-app@0.0.1 stage C:\my-app
> mkdir ./my-dir
The syntax of the command is incorrect.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "stage"
npm ERR! node v6.4.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! my-app@0.0.1 stage: `mkdir ./my-dir`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.0.1 stage script 'mkdir ./my-dir'.
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 my-app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mkdir ./my-dir
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs my-app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls my-app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\my-app\npm-debug.log
如果这行不通,是否有一种跨平台友好的方法来初始化一个空目录?
这个模块可能会解决你的问题: https://www.npmjs.com/package/mkdirp
Npm 使用 windows mkdir 命令,而不是 linux。使用
"setup": "mkdir .\my-dir"
使用反斜杠。
你也可以安装cygwin和运行:
/cygwin64/bin/mkdir -p mydir
您可以使用 npx plus mkdirp 相对轻量级、便携的解决方案,无需全局安装
将此添加到 package.json
:
"scripts": {
"create-dir": "npx mkdirp _site/assets",
}
然后像这样使用:
$ npm run create-dir