3

This works on the Powershell command line:

C:\rootProject\> copy ZZZ.js -destination ZZZXXX.js

But this doesn't work:

package.json

"scripts": {
  "copy-script": "copy ZZZ.js -destination ZZZXXX.js"
}

Run script:

C:\rootProject\> npm run copy-script

ERROR

The syntax of the command is incorrect.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-module-imports@1.0.0 test-copy: `copy ZZZ.js -destination ZZZXXX.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test-module-imports@1.0.0 test-copy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\USER\AppData\Roaming\npm-cache\_logs\2019-11-29T09_29_59_261Z-debug.log
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

1 Answers1

5

It needs the powershell term before the command inside the script.

package.json

"scripts": {
  "copy-script": "powershell copy ZZZ.js -destination ZZZXXX.js"
}

Now it works:

C:\rootProject\> npm run copy-script
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
  • 3
    If you're often creating npm scripts whereby; cross-platform support is not a requirement, and you regularly utilize Powershell specific commands, then consider changing the default `cmd.exe` shell that npm uses on Windows to `pws` by setting the [`script-shell`](https://docs.npmjs.com/misc/config#script-shell) config. Examples of how to do that can be found in [this answer](https://stackoverflow.com/questions/55300421/how-can-i-make-npm-projects-with-bash-shell-commands-work-on-windows?#answer-55303370). You'll probably negate the need to add the `powershell` term before a command. – RobC Nov 29 '19 at 10:46