VSCode complains that resolving my environment takes too long

Viewed 13580

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 Answers

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

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

Open VS Code from a terminal:

code .

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

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.

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.

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

Related