Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Doesn't work on Windows #392

Closed
codefoster opened this issue Jun 24, 2015 · 10 comments
Closed

Doesn't work on Windows #392

codefoster opened this issue Jun 24, 2015 · 10 comments

Comments

@codefoster
Copy link

I get an error in gh/lib/exec.js:24 at...

stdout: exec.stdout.toString().trim()

Stating that it Cannot read property 'toString' of null

@henvic
Copy link
Member

henvic commented Jun 24, 2015

Hi @codefoster,

can you please tell the command you're trying to invoke and doesn't work (or doesn't it work at all?), the complete exception error, and both your gh and node versions?

node --version
gh --version

Thanks.

@codefoster
Copy link
Author

I tried a few different commands and they do the same thing. The last one I tried was gh gi.

node --version //I use nodist (like nvm) and tried 10.33,12.2,and 12.4
gh --version //can't tell... it throws the same error

@henvic
Copy link
Member

henvic commented Jun 25, 2015

Okay, please try the following:

nodist 0.12
npm uninstall -g gh
npm install -g gh
gh

If it still doesn't work, please copy & paste the entire stack trace in this issue.

@codefoster
Copy link
Author

Sorry for the delay. Didn't work. Here's the full trace...

C:\code> gh
C:\bin\nodist\bin\node_modules\gh\lib\exec.js:24
        stdout: exec.stdout.toString().trim(),
                           ^
TypeError: Cannot read property 'toString' of null
    at Object.exports.spawnSync (C:\bin\nodist\bin\node_modules\gh\lib\exec.js:24:28)
    at Object.exports.getNodeModulesGlobalPath (C:\bin\nodist\bin\node_modules\gh\lib\configs.js:29:23)
    at Object.exports.run (C:\bin\nodist\bin\node_modules\gh\lib\cmd.js:216:17)
    at Object.<anonymous> (C:\bin\nodist\bin\node_modules\gh\bin\gh.js:20:26)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)

@henvic
Copy link
Member

henvic commented Jul 13, 2015

@codefoster,
sorry for the delay.

I have been pretty busy.
There's no way for me to test on Windows any time soon. I am really sorry about that.

Here are the things that I know might solve or mitigate your issue:
a. update to the latest versions of gh and node.js
b. remove your user's .gh.json
c. after gh user --login open your user's .gh.json and look for the key plugins_path. Either make it empty ("") or set it to whatever value npm root -g returns (so you can still use plugins such as gh-jira).

@flyeven
Copy link

flyeven commented Aug 20, 2015

On windows 8.1, has the same stdout.toString() Cannot read property 'toString' of null error.

nodejs v0.12.7, the last gh.

@ZoltanTakacs
Copy link

Hey @henvic, @zenorocha,

This is an issue with libuv, it doesn't search for *.bat or *.cmd files. I've debugged it and found that child_process.spawnSync() fails with ENOENT on Windows OS.

Please see the same issue here: nodejs/node-v0.x-archive#25330

As a temporary workaround I've modified the gh/lib/exec.js # spawnSync with the code below:

exports.spawnSync = function(cmd, args, options) {
    var exec;

    logger.debug('spawnSync: ' + cmd + ' ' + args.join(' '));

    if (cmd !== 'git') {
        exec = child_process.spawnSync(cmd + '.cmd', args, options);
    } 
    else {
        exec = child_process.spawnSync(cmd, args, options);
    }

    return {
        stdout: exec.stdout.toString().trim(),
        stderr: exec.stderr.toString().trim(),
        status: exec.status
    };
};
$ node -v && npm -v
v0.12.7
2.11.3

Hope that helps for Win users. :)

Related to: #349

Nilzor pushed a commit to Nilzor/gh that referenced this issue Sep 21, 2015
@Nilzor
Copy link

Nilzor commented Sep 21, 2015

Thanks @ZoltanTakacs - I created a pull request based on your hack, while adding a check for if the users is running on Windows #411

@henvic henvic closed this as completed in 535feb3 Sep 22, 2015
@henvic
Copy link
Member

henvic commented Sep 22, 2015

@Nilzor, @ZoltanTakacs et al.,
I have made some small changes to make it first try without .cmd, then try with .cmd just because I want to avoid it breaking in the future. Can you guys verify it for me?

PS: if you stop using Windows I'll buy you a 🍺 😆

@Nilzor
Copy link

Nilzor commented Sep 24, 2015

Works fine!

I'll take that beer anyway ;) 🍺

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants