18

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.

Tom Granot
  • 1,840
  • 4
  • 22
  • 52

4 Answers4

44

Heroku is currently under update but try this should work: heroku login -i

Bwvolleyball
  • 2,593
  • 2
  • 19
  • 31
dickenzoh
  • 541
  • 4
  • 4
  • 1
    Thanks this helped! I noticed that the command `heroku login -i` is documented, but when I searched for `Warning: Cannot open browser.` I ended up here. – Keehl Feb 25 '20 at 16:05
  • 1
    this saved me lots of time, working still January 2021 – CodeBug Jan 08 '21 at 09:53
7

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.

Tom Granot
  • 1,840
  • 4
  • 22
  • 52
0

You can also generate a non-expiring OAuth token and pass it to the CLI via an environment variable. See my answer here for how to do it. You may already have an API key. Check in your Heroku web dashboard under Account Settings > Account > API Key.

Roger Marlow
  • 349
  • 3
  • 9
0

Windows user here, switching from git bash to windows cmd worked for me, using just heroku login.