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

我正在为happyfuntimes apibuild设。 我已经广泛使用它,但我突然收到一个错误,停止一切工作。 该错误的日志是:

/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上的caching。 我已经尝试了多个不同版本的节点和npm。 我正在运行Mac 10.9.5。 唯一的相关错误,我可以find这个消息处理咕噜,我已经尝试了在该范围内的各种解决scheme。 如果任何人都可以指出我的错误是什么,我会感激不尽! 谢谢阅读!

如果你浏览github仓库,你可以findcomputername.js和错误的上下文:

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

我认为这个函数调用utils.execute是失败的,所以res没有价值。 也许'scutil'不存在于你的系统上。

我build议像这样添加错误检查代码:

 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]; } }); } 

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