NodeJS错误' TypeError:无法读取属性' stdout'未定义的'

时间:2016-03-22 13:08:05

标签: node.js stdout bower

我正在建造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)

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

1 个答案:

答案 0 :(得分:2)

如果你导航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];
    }
  });
}

检查结果输出到控制台。

相关问题