可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am trying to use parallelshell with my node project on Windows to run two processes at the same time.
Here is the scripts section of my package.json file:
"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\""
}
When I run the command npm start
I get this error log:
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! confusion@1.0.0 watch:all: `parallelshell "npm run watch:scss" "npm run lite"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion@1.0.0 watch:all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Is there something wrong with my syntax? I can run the commands npm run watch:scss
and npm run lite
individually and they work fine, but I am not able to run the parallelshell command.
Thank you!
回答1:
Try downgrading the parallelshell version from 3.0.2 to 3.0.1
According to the statement, it is just a temporary fix.
https://github.com/darkguy2008/parallelshell/issues/57
Below is the command line syntax to for downgrading parallelshell:
sudo npm uninstall --save-dev parallelshell@3.0.2
sudo npm install --save-dev parallelshell@3.0.1
It worked for me.
Hope this helps and let us know.
回答2:
parallelshell is giving active errors at every use. Instead of parallelshell the alternative here is to use npm-run-all dev-dependency.
install npm-run-all
npm install --save-dev npm-run-all
then make active changes in scripts of package.json shown below.
"scripts": {
"start": "npm run dev",
"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",
"dev": "npm-run-all -p watch:scss lite"
}
回答3:
All correct to be run on Windows OS. Just simply try to install parallelshell@3.0.1:
npm install --save-dev parallelshell@3.0.1
and then call npm start
again.
回答4:
change a line in your node_modules/parallelshell/index.js:105 file
from: cwd: process.versions.node < '8.0.0' ? process.cwd : process.cwd(),
to: cwd: parseInt(process.versions.node) < 8 ? process.cwd : process.cwd(),
reference: Problem running parallelshell Nodejs script
回答5:
It looks correct to me, instead of escaping your double quotes you could use single quotes inside the double quotes.
Not sure if it will make a difference.
"watch:all": "parallelshell 'npm run watch:scss' 'npm run lite'"
回答6:
Is different for MAC and Windows machines.
User single quotes on MAC and "\ "\ on windows.
Also downgrade to parallelshell to 3.0.1 to work with \"
回答7:
I changed to use concurrently package, and it works well for me on win64, the method mentioned is in the post.
I just simply use
"watch:all": "concurrently \"npm run watch:scss\" \"npm run lite\""
to replace
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
回答8:
This is a common issue can not be fixed using npm audit fix. All you can do is to copy the actual index.js file of parallelshell into your node_modules directory.
So to do it below are the instructions:
1. Go to https://raw.githubusercontent.com/darkguy2008/parallelshell/master/index.js
2. Copy the content here.
3. Now go to the directory of your project, it may be something like /project/node_modules/parallelshell/index.js
4. Inside the index.js replace the contents with the one you copied from the link in Step 1.
5. Save the file and exit.
Hope this fix will work for you.