简体   繁体   中英

mkdir -p doesn't work in package.json script on Windows

Say, we have a React app, and there's a script in package.json:

"scripts": {
    "create-images-dir": "mkdir -p distrib/images"
}

If to run this script via npm run create-images-dir on Linux, it works fine. But trying to run it on Windows environment in git-bash or Cygwin terminal, I'm getting this error:

The syntax of the command is incorrect.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Exit status 1

Same error with setting --parents instead of -p . Without -p parameter, it works, so it stumbles on -p . But at the same time, the command from script works fine if typed manually in terminal:

mkdir -p distrib/images

For me, it looks like some symbol escaping occurs when command is translated from script to execution, or different processing of nested directories on Windows, but I have no idea what exactly it is. Am I doing something wrong?

这就是存在mkdirp软件包的原因-将其添加为dev依赖项,并在脚本中使用二进制mkdirp而不是平台特定的mkdir

On Linux the correct syntax to create directory recursively is:

mkdir -p distrib/images

On Windows you don't have to specify -p .

You can use mkdirp package as suggested by @dmfay or use os in your package.json to not include -p when on windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM