[Windows] not working in npm script if use '
rendomnet opened this issue · 5 comments
If I use npm script
"copy": "cpy './package.json' dist"
npm run copy
it will give me error
Cannot copy
'./package.json': the file doesn't exist
But if I remove ' like this cpy ./package.json dist
it will run correctly
Windows 10
Node 10.24.1
@rendomnet You can escape a double quote "copy": "cpy \"./package.json\" dist"
FYI --
Removing the single quotes surrounding the paths resolved the issue for me.
Using the example from the OP:
"copy": "cpy ./package.json dist"
I had the same problem. I think this is a documentation thing, as the README e.g. in npmjs says
:
Examples
Copy all .png files in src folder into dist except src/goat.png
$ cpy 'src/*.png' '!src/goat.png' dist <-- here we have single quotes that cause the problems
Copy all .html files inside src folder into dist and preserve path structure
$ cpy '**/*.html' '../dist/' --cwd=src --parents <-- here we have single quotes that cause the problems
:
but as @jhildenbiddle wrote, the single quotes are unnecessary (if the paths don't contain spaces - in that case escaping double quotes around the paths will solve the problem as @whizkidwwe1217 wrote)
So: wouldn't it be a good idea to update the README?
FWIW, I had a process running locally on Windows and on a TeamCity build agent on linux. Removing single quotes made it work OK on Windows but not on linux, Whereas using escaped double quotes as per @whizkidwwe1217's answer worked on both platforms.