NodeJS Error 'TypeError: Cannot read property 'stdout' of undefined'

NodeJS Error 'TypeError: Cannot read property 'stdout' of undefined'

我正在为 happyfuntimes api 建设。我已经广泛使用过它,但我突然收到一个错误,导致一切无法正常工作。错误日志是:

/Applications/HappyFunTimes.app/Contents/hft/lib/computername.js:38
    computerName = res.stdout.split()[0];
                      ^

TypeError: Cannot read property 'stdout' of undefined
    at /Applications/HappyFunTimes.app/Contents/hft/lib/computername.js:38:23
    at ChildProcess.<anonymous> (/Applications/HappyFunTimes.app/Contents/hft/lib/utils.js:67:7)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:818:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:469:12)

我知道问题不在于代码,因为它有效 elsewhere.I 已多次尝试卸载并重新安装 happyfuntimes、node、npm 和 bower。我已经清理了节点和 npm 上的缓存。我尝试了多个不同版本的节点和 npm。我是 运行 Mac 10.9.5。我能找到的唯一与此消息相关的错误处理 grunt,我已经尝试了该范围内的各种解决方案。如果有人能指出这个错误的大致正确方向,我将非常感激!感谢阅读!

如果您浏览 github 存储库,您可以找到 computername.js 和错误的上下文:

if (process.platform.toLowerCase() === 'darwin') {
  utils.execute('scutil', ['--get', 'ComputerName'], function(err, res) { 
    computerName = res.stdout.split()[0];
  });
}

我认为函数调用 utils.execute 失败了,因此 res 没有任何价值。也许 'scutil' 在您的系统上不存在。

我建议添加这样的错误检查代码:

if (process.platform.toLowerCase() === 'darwin') {
  utils.execute('scutil', ['--get', 'ComputerName'], function(err, res) {
    if (err) {
        console.log("Error in scutil: " + err);
    } 
    else {
        computerName = res.stdout.split()[0];
    }
  });
}

并检查输出到控制台的结果。