Stal G
Stal G

Reputation: 138

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

I am building for the happyfuntimes api. I have worked with it extensively already but I am suddenly receiving an error that stops everything from working. The log for the error is :

/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)

I know the problem isn't with the code because it works elsewhere.I have tried uninstalling and reinstalling happyfuntimes, node, npm, and bower multiple times. I have cleaned the cache on both node and npm. I have tried multiple different versions of node and npm. I am running Mac 10.9.5. The only related errors I can find to this message deal with grunt and I have tried various solutions in that range. If anyone can point me in the general right direction for what this error is about I would be super grateful! Thanks for reading!

Upvotes: 3

Views: 3665

Answers (1)

Oliver
Oliver

Reputation: 11597

If you navigate the github repository you can find computername.js and the context of the error:

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

I think that the function call utils.execute is failing, and so res has no value. Perhaps 'scutil' does not exist on your system.

I suggest adding error checking code like this:

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

And examining the resultant output to the console.

Upvotes: 2

Related Questions