我正在尝试将并行 shell 与Windows上的节点项目一起使用,以同时运行两个进程。
这是我的package.json文件的脚本部分:
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
}
当我运行
npm start
命令时,出现以下错误日志:TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type string. Received type function
at normalizeSpawnArguments (child_process.js:420:11)
at spawn (child_process.js:522:38)
at C:\Users\Daniel\Documents\development\online_classes\coursera_uhk_web_dev\Bootstrap4\conFusion\node_modules\parallelshell\index.js:104:17
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\Users\Daniel\Documents\development\online_classes\coursera_uhk_web_dev\Bootstrap4\conFusion\node_modules\parallelshell\index.js:100:6)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] watch:all: `parallelshell "npm run watch:scss" "npm run lite"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] watch:all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我的语法有问题吗?我可以分别运行命令
npm run watch:scss
和npm run lite
,它们可以正常工作,但是我无法运行parallelshell命令。谢谢!
最佳答案
尝试将并行Shell版本从3.0.2降级到3.0.1
根据声明,这只是一个临时解决方案。
https://github.com/darkguy2008/parallelshell/issues/57
以下是降级 parallelshell 的命令行语法:
sudo npm uninstall --save-dev [email protected]
sudo npm install --save-dev [email protected]
它为我工作。
希望这会有所帮助,并让我们知道。
关于node.js - 您如何在npm脚本中正确使用parallelshell?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51060296/