运行并行Shell Node.js脚本时出现问题

时间:2018-11-24 19:24:28

标签: node.js json sass npm-scripts lite-server

在我的package.json文件中,我具有以下脚本:

"scripts": {
    "start": "npm run watch:all",
    "test": "echo \"Error: no test specified\" && exit 1",
    "lite": "lite-server",
    "sass": "node-sass -o sass/ css/",
    "watch:sass": "onchange 'sass/*.scss' -- npm run sass",
    "watch:all": "parallelshell 'npm run watch:sass' 'npm run lite'"
  }

每当我运行代码时,都会出现以下错误消息:

 crs@1.0.0 start /home/hazem/crs
> npm run watch:all


> crs@1.0.0 watch:all /home/hazem/crs
> parallelshell 'npm run watch:sass' 'npm run lite'

child_process.js:422
    throw new ERR_INVALID_ARG_TYPE('options.cwd', 'string', options.cwd);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type string. Received type function
    at normalizeSpawnArguments (child_process.js:422:11)
    at spawn (child_process.js:537:38)
    at /home/hazem/crs/node_modules/parallelshell/index.js:104:17
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/hazem/crs/node_modules/parallelshell/index.js:100:6)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! crs@1.0.0 watch:all: `parallelshell 'npm run watch:sass' 'npm run lite'`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the crs@1.0.0 watch:all 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!     /home/hazem/.npm/_logs/2018-11-24T19_19_24_809Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! crs@1.0.0 start: `npm run watch:all`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the crs@1.0.0 start 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!     /home/hazem/.npm/_logs/2018-11-24T19_19_24_823Z-debug.log

那么,在这种情况下,可能是什么问题?脚本有问题吗?还是nodejs中Parallelshell脚本中的错误?

3 个答案:

答案 0 :(得分:10)

Parallelshell有一个问题,必须手动修复;

转到文件:

node_modules/parallelshell/index.js

然后更改此行:

cwd: process.versions.node < '8.0.0' ? process.cwd : process.cwd(),

对此:

cwd: parseInt(process.versions.node) < 8 ? process.cwd : process.cwd(),

完成了!

答案 1 :(得分:0)

它对我有用,因为我遇到了类似的问题,并行shell 3.2.2无法应付我的节点,因此我必须对其进行降级

答案 2 :(得分:0)

cwd:

parseInt(process.versions.node) < 8 ? process.cwd : process.cwd() 

如果执行此操作后仍然遇到问题,则必须使用以下命令降级Paralleshell的版本:

sudo npm install --save-dev parallelshell@3.0.1

对我有用。