35

When I launch VSCode from the dock, it always complains that

Resolving your shell environment is taking very long. Please
review your shell configuration.

and then a bit later

Unable to resolve your shell environment in a reasonable time.
Please review your shell configuration.

According to this page, Resolving Shell Environment is Slow, the first message is displayed if .bashrc takes more than three seconds and the second is displayed if it takes longer than ten seconds.

I opened a terminal in VSCode and sourced my .bashrc file

dpatterson@dpconsulting$ time source ~/.bashrc
real    0m1.448s
user    0m0.524s
sys     0m0.671s

dpatterson@dpconsulting$ 

As you can see, it takes less than 1.5 seconds.

Environment:

  • MacOS Mojave 10.14.6
  • VSCode 1.53.0

Hopefully someone knows what is causing this.
Barring that, maybe someone can point me to the code that actually generates these errors.

TIA

7
  • That's still a really long time to source your .bashrc. Mine runs in sub-second time. A reasonable guess is that the 1.5 seconds plus whatever time it's taking to launch your shell environment (WSL maybe?) + sourcing your bashrc is exceeding the threshhold. I don't see enough info in there to do more than guess, but... maybe move your .bashrc to .bashrc-old and see if that fixes it? If it does, then you know to target your .bashrc complexity. If it doesn't, then it's whatever is happening before (like launching WSL). Or maybe you're memory constrained, etc. etc. Commented Feb 11, 2021 at 20:40
  • WSL is definitely not involved. I'm on a Mac. Commented Feb 11, 2021 at 23:13
  • Yep. Something in my bash initialization (it does do a lot). Is there any way for my .bashrc to know that it's VSCode starting it up? Commented Feb 11, 2021 at 23:19
  • 1
    Issue is officially being tracked here github.com/microsoft/vscode/issues/108804. Hopefully, there should be a fix/patch/workaround soon. Commented Apr 25, 2021 at 5:22
  • 2
    The fix for me ended up being to comment out the nix and ghcup lines from my zshrc (haskell stuff) Commented Nov 2, 2021 at 22:43

12 Answers 12

24

encountered the same situation and find the issue: https://github.com/microsoft/vscode/issues/113869#issuecomment-780072904

In my .bashrc, I extract nvm load code to the condition function ref in the issue, solved this problem:

function load-nvm {
  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
  [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  [[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
}

# nvm
if [[ "x${TERM_PROGRAM}" = "xvscode" ]]; then 
  echo 'in vscode, nvm not work; use `load-nvm`';
else 
  load-nvm
fi

4
  • it works for me
    – King.
    Commented Dec 8, 2021 at 7:46
  • Where is the file / what is the name of the file that I should be adding this load-nvm function?
    – Emilio
    Commented Feb 27 at 3:12
  • If you are on mac, ~/.zshrc. Note that this change will only be useful if you have nvm (node version manager) installed on your system and the lines that load nvm and bash completion are already in the file. It's saying "only run these if this isn't loaded by Visual Studio, so if you're currently not running them at all there is of course nothing to gain, the env is loading slowly for a different reason.
    – nikobelia
    Commented Mar 26 at 9:22
  • Surprisingly for me export NODE_OPTIONS=--openssl-legacy-provider line in my rc file was causing the issue
    – yeralin
    Commented May 8 at 14:57
14

If you don't want to mess with your environment, the easiest path to fixing this is to change the Application: Shell Environment Resolution Timeout setting on VSCode to make it longer.

Bumping it up from 10 seconds to 30 fixed my problem.

4
  • It looks like this may have worked. I'll accept this as the correct answer somewhere down the road if the results are consistent. Thanks. Commented Dec 1, 2023 at 20:51
  • This doesn't work for me. I'm running nvm so the other answer seems more accurate. Commented Apr 29 at 13:08
  • That immediately worked for me on macOS Sonoma 14.5. Commented Jul 4 at 11:32
  • It is now under: Settings > Application > Experimental > Shell Environment Resolution Timeout
    – Igbokwenu
    Commented Sep 30 at 10:01
5

OSX Work-around

Background

If VS Code is started via an OSX (or Linux) GUI interface and there's a shell rc process that takes more than 10 seconds to complete during start-up (e.g. nvm) VS Code simply stops trying to start-up that shell.

Work-around

The two known solutions are to either get rid of the process that takes more than 10 seconds or start VS Code from the command line (i.e. code .).

This work-around is for those of us on OSX who —for whatever reason— explicitly don't/can't get rid of the 10+ second process and who —again, for whatever reason— start VS Code via the GUI.

While the following is less desirable than VS Code just having a configuration that we can change, it's still better than having to remember to run code . from the terminal, and it's much, much better than not using nvm (or switching to an alternative).

Note: The file extension does need to be changed between .command and .app several times — this is not a mistake! ;)

  1. Create a new file with the following:

    #!/bin/sh
    
    code .
    
  2. Save the file with a .command extension in your "Applications" directory, e.g. ~/Applications/vs-code-cli-starter.command.

  3. In a terminal, change that new file's permissions:

    chmod +x fileName.command
    
  4. From Finder, right click-on your new app/command and select "Get Info", then repeat with your actual VS Code application.

  5. Drag the big icon from the "Preview" section of the actual VS Code's "Get Info" to the small icon in the upper-left of your newly created app/command's "Get Info". where to drag the source icon from and where to drag it to

  6. Close the two "Get Info" panels.

  7. In the "Applications" directory, update the file extension from .command to .app, e.g. vs-code-cli-starter.app.

  8. Drag the newly created app's icon to your dock.

  9. In the "Applications" directory, swap the file extension back from .app to .command, e.g. vs-code-cli-starter.command.

  10. Enjoy

2
  • 1
    This is a good work around but it leaves a running terminal which I don't like. Commented Nov 19, 2022 at 2:04
  • Sweet workaround. I didn't know about the icon dragging. Is it possible to close the terminal with the script as well?
    – Bryan
    Commented Mar 5 at 5:50
3

Open VS Code from a terminal:

code .
1
  • 1
    This doesn't answer the question. @David Peterson wants to know what the issue with his .rc file is, not just how to avoid getting the issue with vscode. Commented Jul 13, 2022 at 23:02
2

Restarting VSCode on BigSur works for me.

You can also check your user settings to make sure it matches the path of the shell that your terminal uses.

Check https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch for other troubleshooting steps.

2
  • Happened for me after a system update. VSCode was open on reboot, so it restarted it, but apparently not correctly. Restart VSCode solved the issue, as stated.
    – rickb
    Commented Nov 3, 2021 at 21:13
  • 3
    I had to close VSCode, restart my Mac and then open VSCode, then close it and reopen it again before it started working properly. But it is now working. Don't give up fellow restarters - if at first you don't succeed, restart, restart, restart again! Commented Nov 11, 2021 at 17:56
2

For those who uses zsh, .ohmyzsh and powerlevel10k prompt:

  1. Get all your exports EXCEPT export ZSH= and nvm stuff and put them in the bottom of .zshrc file.

  2. Insert this line at the top: if [[ "$VSCODE_PID" = "" ]]; then

  3. Before your exports at the bottom, insert an fi (end if)

Now, all your ohmyzsh, nvm and ohmyzsh themes are not loaded when VSCode initializes (the built in terminal still works fine, with ohmyzsh).

In my case, outside that if/fi there is only exports for PATH, LDFLAGS and CPPFLAGS.

Thanks to M Imam Pratama answer.

1

it's a very common error or we can say complain by vs code so here is the solution - do not open vs code directly from its icon or directly from application instead you can do is just open vs code from terminal/cmd obviously for linux/windows respectively by typing this command -> $ code . if this command is not working then reinstall the vs code and check all the boxes before installing it will also allows you to open vs code from folder directly by clicking right side of mouse and just click open this folder with other application and select vs code.

1

For Linux:

if [[ "$VSCODE_PID" = "" ]]; then
  echo "slow or blocking operations"
fi

Thanks to Hemisu's answer.

0

If you are using ZSH, it could be because there is a blocking script. Open a new Mac terminal window as shown below(The top part of the window/tab will show the blocking script/command):

The top part will show the blocking script/command

You can use the command nano ~/.zshrc and comment out the command/script then restart your terminal.

0

Go to project location and open with code . in terminal (if you are in linux) or cmd (if you are in windows.) That should resolve this issue.

When directly opened from vscode app it happens, even I have faced this.

0

Do these 2 steps, this worked for me

From VS code

  1. Press Cmd+Shift+P then write and select shell Command: Uninstall 'code' command from PATH
  2. press Cmd+Shift+P then write and select shell Command: Install 'code' command from PATH.

This resolved my problem :)

-1

In Linux, you can open "alacarte" and make a new shortcut with the command "code" and click the box "Open in a terminal".

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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