Reputation: 998
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?
Upvotes: 4
Views: 3932
Reputation: 348
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.
Upvotes: 1