node.js - 运行 parallelshell Nodejs 脚本时出现问题

标签 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 脚本中的错误?

最佳答案

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(),

完成了!

关于node.js - 运行 parallelshell Nodejs 脚本时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53461626/

相关文章:

javascript - 将 json 与 jquery Ajax 一起使用不会返回任何内容

ruby-on-rails - Assets 管道缓存 CSS?

html - CSS中带有em单位的响应宽度

json - 使用JSON4S在Scala中对案例对象进行反序列化

json - 使用 ASP Xtreme Evolution 在经典 ASP 中解析 JSon

css - 如何让css不重复同一个类?

node.js - Node.JS fork 的最佳方法?

node.js - 如何使用 express/node 确认电子邮件地址?

javascript - 为什么 ISO 日期转换在 javascript 环境中不一致以及如何修复?

node.js - mongodb更新和$set覆盖文档