Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Powershell commands to an NPM script?

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! [email protected] test-copy: `copy ZZZ.js -destination ZZZXXX.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
like image 241
cbdeveloper Avatar asked Sep 21 '25 03:09

cbdeveloper


1 Answers

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
like image 174
cbdeveloper Avatar answered Sep 22 '25 15:09

cbdeveloper