【问题标题】:Problem running parallelshell Nodejs script运行parallelshell Nodejs脚本的问题
【发布时间】:2019-04-26 22:45:00
【问题描述】:

在我的 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 脚本中的错误?

【问题讨论】:

  • 在项目 github repo 中查看未解决的问题 #67
  • @RobC 欣赏,修复!

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


【解决方案1】:

cwd:

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

如果你这样做后仍然遇到问题,你必须使用这行来降级paralleshell的版本:

sudo npm install --save-dev parallelshell@3.0.1

它对我有用。

【讨论】:

    【解决方案2】:

    Parallelshell 存在问题,必须手动修复;

    转到文件:

    node_modules/parallelshell/index.js:105
    

    然后改变这一行:

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

    到这里:

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

    完成了!

    【讨论】:

    • 如果您找不到此行,请查看第 105 行(index.js)。
    【解决方案3】:

    它对我有用,因为我遇到了类似的问题,parallelshell 3.2.2 无法处理我的节点,所以我必须降级它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      相关资源
      最近更新 更多