16

Wondering if you could assist. Really challenging in determining a solution to this from my research.

I downloaded Visual Studio Code two weeks ago, and have come across an error when I try to debug a file. The file appears to open but once I run the debugger it shows accordingly:

enter image description here

Variable ${workspaceFolder} can not be resolved. Please open a folder.

Can't seem to find or replicate a similar solution. I've also tried to reinstall Visual Studio Code (no easy feat). I'm trying to at least understand the problem and its source.

The file is a .js file that I've been working on; running a simple function. It is not meant to operate in tandem with a larger workspace/program.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Andrew Trac
  • 163
  • 1
  • 1
  • 4

7 Answers7

17

In VScode go to file --> Add folder to workspace and select the folder where the program files are located.

Meysam
  • 409
  • 4
  • 14
  • So after I did this, I could solve the second part of the problem with VSCODE with this post https://stackoverflow.com/questions/60387842/how-do-i-compile-and-run-a-c-sharp-code-in-vscode-linux-ubuntu by editing the program: and substituting with the net5.0 core, etc. – Michael Seifert Mar 16 '21 at 21:42
  • 1
    What do you mean by "program files" ? The .exe file ? – Julien Jul 02 '22 at 06:57
3

I know this question is very old already and the answers may have been correct but none worked for me on vscode v1.57.1 at the time of this comment on 30.06.2021

I had to replace ${workspaceFolder} with ${workspaceFolder:my-folder-name} in my *.code-workspace file

Ref: Variables scoped per workspace folder

omostan
  • 840
  • 8
  • 9
2

If you are using the latest Visual Studio 1.44, make sure to upgrade to 1.44.2.

The issue microsoft/vscode issue 94725 has been resolved.
It featured the same error message:

https://user-images.githubusercontent.com/9964210/78838126-65c76d80-79ed-11ea-8572-a092f1576dbc.png

After some investigation the problem is the following for the workspace configuration our debug extensions appends the following attribute

__workspaceFolder:'${workspaceFolder}'

And the configuration resolver properly tries to resolve this and complains because the scope of the folder is not specified.
In a multi root workspace scope has to be specified, otherwise the resolver does not know against which folder to resolve the variables.

Proposed fix: the node extension which adds this attribute should scope it if it sees that we are in a multi root folder.
So instead of ${workspaceFolder} use ${FOLDER_NAME:workspaceFolder}.

This is fixed in commit ae97613.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I get `error cwd ${FOLDER_NAME:workspaceFolder} does not exist`. Part of `workspace.json` is `{"path": "../../../../.oh-my-zsh/custom"}` -> relative path, created by `File Add Folder to Workspace`. – Timo May 22 '21 at 09:39
  • adding to the comment above next to `cwd` : `"program": "${file}"` – Timo May 22 '21 at 09:59
  • @Timo OK. Can you ask a separate question with the version of your OS and VSCode used? – VonC May 22 '21 at 15:29
  • ok, I get the error after having deleted `launch.json`. I just want to use `workspace.json` and set `launch` config there. I get the error with `zshdb` and did not have a config entry in `launch.json`, but in `workspace.json`. – Timo Jun 07 '21 at 19:49
  • @Timo So did you resolve your issue? (if not, that would be better addressed in a separate question, as I commented above) – VonC Jun 07 '21 at 19:51
  • New situation: if I put the config in `launch.json` in my `code/user`folder, I get in the debug selection a `bash-deb (User)` and start it. Then it works. If I start `bash-deb(workspace)` with same config in `workspace.json` then I get `unable to determine workspace folder`. So this might be a new question as it should work with `(workspace)`. – Timo Jun 09 '21 at 07:29
  • Another finding is that with `python` and `powershell` debug it works in both `(workspace)` and `(user)` debug mode. – Timo Jun 09 '21 at 07:58
  • @Timo Indeed, that would be best addressed as a separate question: let me know when you create it, and I will follow it. – VonC Jun 09 '21 at 08:13
  • [New question](https://stackoverflow.com/questions/67910200/vscode-debug-not-working-with-workspace-config) – Timo Jun 09 '21 at 18:57
2

Replace ${workspaceFolder} with ${FOLDER_NAME:workspaceFolder} in your *.code-workspace file. (from [here][1])

By the way, same goes to ${workspaceRoot}, you can replace it with ${FOLDER_NAME:workspaceRoot}.

Any more folder variables ca be fixed with this FOLDER_NAME: prefix? My workspaces did not use them so far.

Worked for me in Version: 1.44.2.

moudrick
  • 2,148
  • 1
  • 22
  • 34
  • As per latest update, it is `${workspaceFolder:}`; [Source](https://code.visualstudio.com/docs/editor/multi-root-workspaces#_debugging) – rehman_00001 Aug 08 '23 at 07:22
0

I recently had this problem and so did I read the answers above but being a beginner I was unable to solve it .In my answer I don't have exactly what you should do but I will show what worked for me.

  1. Go to the explorer and you will see there is no folder added.
  2. Browse for .vscode folder and select it.
  3. Issue solved {this atleast worked for me.It**(.vscode)** had .json extension file in it}.
DCCoder
  • 1,587
  • 4
  • 16
  • 29
Prasad_k
  • 1
  • 1
0

I was having the same issue, but I solved it this way: 1- open VS Code as administrator 2- open the sheet 3- debugging with no problem :)

0

enter image description here

I just create a file.json that they can debug.