Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you correctly use parallelshell with npm scripts?

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! [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.

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!

like image 211
dpberry178 Avatar asked Jun 27 '18 10:06

dpberry178


People also ask

How do I run two commands in npm?

&& will run your scripts sequentially while & will run them in parallel. A quick way of doing it is npm run start-watch & npm run wp-server . This will run the first command as a background thread. This works really well when one of the commands is not long running and does not need to be manually exited later.

Where do I put npm scripts?

You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/.


2 Answers

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 [email protected]

sudo npm install --save-dev [email protected]

It worked for me.

Hope this helps and let us know.

like image 77
Sridhar C Avatar answered Sep 27 '22 19:09

Sridhar C


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"
  }
like image 44
Rakesh Chary Bangaroj Avatar answered Sep 27 '22 18:09

Rakesh Chary Bangaroj