I found some public question which treat this topic, but I didn't get a specific solution.

I have this error message when I try to deploy my files from local to my org.

Error: INVALID_SESSION_ID: Session expired or invalid

It's the first time it happens. I have opened session on this org but I cannot deploy files from local. I tried to do the solution using this command on terminal:

lsof -i tcp:1717

But it does not work.

Any idea? Thanks.


3 Answers 3


I ran into this issue after I had to change my password in the sandbox. I just ran this command to fix it:

sfdx force:auth:web:login -a <alias> -d -r https://test.salesforce.com

This will open up your browser to login to the sandbox. I was able to deploy to the org after doing this.

(The -r lets you login to a sandbox. Without it, your browser will open to login.salesforce.com.)

  • Just today I had same problem on another deployment and it worked! Thank you dazmae!
    – CPS
    Mar 10, 2021 at 8:23
  • Thanks - this resolved my issue. Although i didn't have to change my password.
    – Asif K
    Mar 10, 2021 at 21:18

I solved it through the following steps-

At the bottom left of your VS Code you will find a small box icon to 'open the org'enter image description here. Just click on that. Wait till the operation finishes. Then try to deploy again.

  • Or sfdx force:org:open or Command-P SFDX: Open Default Org but the real question is why ANY of it is necessary when we have a valid auth token already registered. Why does open work but not push? Aug 24, 2021 at 18:46

In case you're deploying to a scratch org, executing sfdx force:org:list in your terminal should refresh your connections - see thread here

After this command finishes, try deploying again and it should work.

  • sfdx force:org:open works to renew the session, but not list. Aug 24, 2021 at 18:47
  • Have you tried it? I did and it worked for me
    – sskular
    Aug 25, 2021 at 11:33
  • I did, and it didn't refresh the token for whatever reason. Aug 25, 2021 at 15:02
  • Are you working against a scratch org or a sandbox? This trick worked only for scratch orgs. Could be that after some version it stopped working. However, things moved since then and it's been acknowledged as a platform issue and the most up to date recommendation is to follow the github issue for updates: github.com/forcedotcom/cli/issues/899
    – sskular
    Sep 1, 2021 at 11:58
  • Gotcha, if you edit the answer to make that more explicit I can remove my downvote. Sep 1, 2021 at 15:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.