Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何将Powershell命令添加到NPM脚本?_Node.js_Powershell_Npm_Npm Scripts - Fatal编程技术网

Node.js 如何将Powershell命令添加到NPM脚本?

Node.js 如何将Powershell命令添加到NPM脚本?,node.js,powershell,npm,npm-scripts,Node.js,Powershell,Npm,Npm Scripts,这在Powershell命令行上起作用: C:\rootProject\> copy ZZZ.js -destination ZZZXXX.js 但这不起作用: package.json "scripts": { "copy-script": "copy ZZZ.js -destination ZZZXXX.js" } "scripts": { "copy-script": "powershell copy ZZZ.js -destination ZZZXXX.js" } 运

这在Powershell命令行上起作用:

C:\rootProject\> copy ZZZ.js -destination ZZZXXX.js
但这不起作用:

package.json

"scripts": {
  "copy-script": "copy ZZZ.js -destination ZZZXXX.js"
}
"scripts": {
  "copy-script": "powershell copy ZZZ.js -destination ZZZXXX.js"
}
运行脚本:

C:\rootProject\> npm run copy-script
错误

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

在脚本中的命令之前,需要使用
powershell
术语

package.json

"scripts": {
  "copy-script": "copy ZZZ.js -destination ZZZXXX.js"
}
"scripts": {
  "copy-script": "powershell copy ZZZ.js -destination ZZZXXX.js"
}
现在它可以工作了:

C:\rootProject\> npm run copy-script

如果您经常创建npm脚本;跨平台的支持不是必需的,并且您经常使用Puthshell特定的命令,然后考虑更改默认的代码> CMD.exe < /Case> shell,NPM使用Windows来设置代码> > PWS。有关如何做到这一点的示例,请参见。您可能不需要在命令之前添加
powershell
术语。