19

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!

dpberry178
  • 558
  • 6
  • 21
  • 1
    The solution which worked for me is described here: https://stackoverflow.com/a/53467253/6650315 – Klaus Nov 18 '19 at 16:35

10 Answers10

38

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.

Prags
  • 2,457
  • 2
  • 21
  • 38
Sridhar C
  • 631
  • 5
  • 11
7

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"
  }
4

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.

Sansei
  • 93
  • 10
2

This is due to incompatibility of the npm with the version of parallelshell.
Try downgrading it to 3.0.1 by using:

npm i --save-dev parallelshell@3.0.1

Worked for me 100%.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
1

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

0

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'"
0

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 \"

0

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\""

0

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.

  • Please edit your answer. Instead of linking to some code, post the differences between `node_modules/parallelshell/index.js` and your link here. After that put the link at the bottom as a reference. The link may change or break one day. Another suggestion is to use a permalink like this one (linking to the version of index.js at a certain commit): https://raw.githubusercontent.com/darkguy2008/parallelshell/8fd83e217a015b2c8c8e33ff1e836db02b7bfe8e/index.js This link should always display the same content rather than the latest version in the master branch. – Dimitar Nestorov May 05 '20 at 18:00
0

If someone is still running into errors after altering the index.js or after demoting to 3.0.1 version, a better alternative would be using npm-run-all