ubuntuherokuheroku-cli

Heroku login cannot open browser


When attampting to login to Heroku via the CLI, I get:

user@MyMachine:$ sudo heroku login 
heroku: Press any key to open up the browser to login or q to exit: 
Opening browser to https://cli-auth.heroku.com/auth/browser/SOME-HEROKU-TOKEN
Warning: Cannot open browser.
heroku: Waiting for login... !

And the login hangs while waiting for the browser. When I open the link in the browser and try to login, nothing happens in the CLI.

Using the debugging flags yields:

user@MyMachine:~$ sudo HEROKU_DEBUG=true HEROKU_DEBUG_HEADERS=1 heroku login 
heroku: Press any key to open up the browser to login or q to exit: 
Opening browser to https://cli-auth.heroku.com/auth/browser/SOME-OTHER-TOKEN
Warning: Cannot open browser.
    at Object.warn (/snap/heroku/3776/node_modules/@oclif/errors/lib/index.js:33:15)
    at showUrl (/snap/heroku/3776/node_modules/@heroku-cli/command/lib/login.js:132:34)
    at ChildProcess.cp.on.code (/snap/heroku/3776/node_modules/@heroku-cli/command/lib/login.js:145:17)
    at ChildProcess.emit (events.js:193:13)
    at maybeClose (internal/child_process.js:999:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5)
heroku: Waiting for login... !
JSONError: Unexpected end of JSON input while parsing near ' '
    at module.exports (/snap/heroku/3776/node_modules/parse-json/index.js:26:19)
    at HTTP._parse (/snap/heroku/3776/node_modules/@heroku-cli/command/node_modules/http-call/lib/http.js:343:25)

And again, a hang.


Solution

  • I managed to solve this by:

    1. Running as root - sudo su
    2. Adding the /snap/bin folder to my PATH - PATH=$PATH:/snap/bin
    3. Doing heroku login, copying the link into a browser, pressing login

    This leaves me properly connected in the CLI, for some reason. If someone can shed some light on this that would be cool.