Not able to open VS Code from Terminal in my MacBook BigSur11.3.1 - visual-studio-code

Good day community. I have installed VS Code in my MacBook Air M1 chip running on BigSur 11.3.1 but whenever I set the code command in PATH (using Command+Shift+P) it only appears to be working for current session and doesn't work if I restart VSCode. I have to set the code command in PATH again. Please help me in configuring code command permanently so that i can open VSCode from any directory whenever I want. Thanks

I think I have got the solution. After installing VSCode in your Mac (which will be in download folder) move VS Studio Code.app file to Application Folder and then again install the code command in PATH from VSCode(using Command+Shift+P) and thats it.

Related

Visual Studio Code, code command does not start new file

I'm having an issue where if I do code <filename> where the file does not already exist, it does not create a new file.
Normally, vscode would (almost) create a new file, I could write some code, and then save it and it would appear in my file manager. But this just stopped working.
I had a look through all my extensions and uninstalled all the recent extensions. I've reinstalled vscode, still no luck.
I am using windows with wsl, this affects me when running vscode both in windows and in wsl.
Did some googling around, can't find anything useful. Any advice?
I figured out what caused this in case anyone else is having the same problem.
I installed Rust in windows and that seemed to have messed up the code command.
Sorry, can't remember which version it was, I just uninstalled it on windows and noticed that it fixed it.
(p.s: Rust is great, but I have it installed in WSL so don't need it in windows.)
If you are using npm on windows, you can install touch by running npm i -g touch and creating a folder in a specific location by navigating in the location and creating by mkdir <foldername> navigating inside it and using touch <filename>. From there you can simply launch VS Code by running code . in that folder namespace
If you are using WSL (Ubuntu), it comes preinstalled and you can run mkdir <foldername> && touch <filename> && code .
Not exactly what you are looking for but it can work!

Error loading webview: Error: Could not register service workers: TypeError: Failed to register a ServiceWorker for scope

When I update my VSCode to v1.56.2 and open webview, I get these messages:
Error loading webview: Error: Could not register service workers:
TypeError: Failed to register a ServiceWorker for scope
('vscode-webview://867f875b-c5a3-4504-8de2-2e8614bdc0f8/') with script
('vscode-webview://867f875b-c5a3-4504-8de2-2e8614bdc0f8/service-worker.js?platform=electron&id=867f875b-c5a3-4504-8de2-2e8614bdc0f8&vscode-resource-origin=https%3A%2F%2F867f875b-c5a3-4504-8de2-2e8614bdc0f8.vscode-webview-test.com'):
ServiceWorker cannot be started.
How can I solve this issue?
If you are using Ubuntu, there is probably another (maybe hidden) vscode process, which is causing the problem.
Close the vs code first and in terminal try: killall code.
In Windows, you can simply fix this error by clearing the cache for VSCode. Please follow the steps below:
Close VSCode and also kill any background processes running in the task manager.
Go to the file explorer and to the path C:\Users\<user_name>\AppData\Roaming\Code and clear the contents of the folders Cache, CachedData, CachedExtensions, CachedExtensionVSIXs (if this folder exists) and Code Cache.
Open VSCode and you are good to go.
I encountered this issue and am not a Windows user, so this is my resolution:
I found that there was an instance of VS Code open that was erroneously not shown on my dock. I closed this instance and opened a new instance. The problem was gone.
I think the issue happened because I had a VS Code instance open, allowed a software update to run in the background, postponed the restart, opened a new and updated VS Code instance, and the old instance remained open causing conflicts.
OS: Ubuntu 20.04.2 LTS
#tritemio on GitHub has a great answer:
https://github.com/microsoft/vscode/issues/125993#issuecomment-912439561
in short, delete cache folder:
rm -rf ~/.config/Code/Cache
This is a known bug in VS Code 1.56. It happens for some Windows users when running VS Code as an administrator
As a workaround, you can try launching VS Code with the --no-sandbox command line flag:
$ code --no-sandbox
#tritemio, thanks for sharing.
This also seemed to solve my issues on Windows for "Extensions - Details View", "VS Code Release Notes View", "Gitlab integrated Interactive Rebase Editor", etc.
I followed your suggestion and deleted the following folders;
%appdata%\Code - Insiders\Cache
%appdata%\Code - Insiders\Code Cache
On *nix systems, first close VS Code app then run pgrep -f '/Applications/Visual Studio Code.app' | xargs kill to clean up vscode's processes. Reopen vscode and the issue will be gone.
If on macOS, you can run the above command verbatim. If you're not on macOS or installed vscode on a different location, you need to change the argument passed to pgrep. You can run ps auxww | command grep -i --color code to find the path of vscode's running processes.
Happened to me when started code in windows cmd. Closed vs code and opened it from my taskbar shortcut instead, and the error was gone
The simplest solution for this problem in any version of Linux is simply to close other instances of VS code and use only one instance of VS code.
OS: Linux 20.04.3 LTS
I've also encountered the same "Error loading web view" Error.
I've solved this issue by moving "vscode.app" into "Application folder" instead of "Download folder" on macOS.
I'll describe my "symptom" here.
OS: macOS 12.0.1
Installed 2 versions of vscode somehow, 1 under "Application folder", another under "download folder"
Run both vscode at the same time, the "download folder" version has no error display plugin pages, the "Application folder" version has the "Error loading webview" error
Checked and see 2 vscode instances running in the background
What I tried to solve this issue:
Tried to kill "download folder" instance, and the error remains for "application folder" instance
Moved "download folder" to "application folder" and both vscode works correctly on plugin page!
What I suspect on what the problem is?
Maybe these 2 vscode are sharing the same resource(could be some shared file), however they have different permissions since one is under application folder and another is under download folder.
This answer applies if using VSCode in GitHub Codespaces in Firefox or Brave browsers. I had to disable "Enhanced Tracking Protection" for the site, and that is all. To do so, click on the shield icon which is to the left of the displayed web address.
If anyone is using Brave, please turn off the brave shields as well.
For Mac/Apple computer Monteray version the following steps worked for me:
Delete VSCode from downloads folder.
Turn off VSCode
Open Activity Monitor and delete VSCode "Code" process.
Try closing all the process cmd+qof vscode and reopen vscode and everything should work well.
I have just restarted VS code and it worked for me. OS was Windows 10.

vs code not opening up in windows

whenever i try to open my vs code editor, nothing happens it doesn't launch and even there are no errors..!! And i am confused what's wrong here in my vs code. Please anyone help me fix it..!!
Below are the verbose command i typed in the terminal..
C:\Users\Avinash>code . --verbose
[main 2020-05-10T05:17:56.317Z] Error: UNKNOWN: unknown error, mkdir
[main 2020-05-10T05:17:56.318Z] Lifecycle#kill()
[main 2020-05-10T05:17:56.320Z] [File Watcher (node.js)] Error: UNKNOWN: unknown error, stat 'c:\Users\Avinash Maurya\AppData\Roaming\Code\User'
no need of Unistalling, just go to your vscode-setup and reinstall it. (by this procedure all of your's settings, files , extensions etc.. will be restored as it is.)
I also came across the same issue.
Uninstalling and Reinstalling it again worked out and all my extensions were there already(that was strange).
You may want to try "Run as Administrator".
try code --no-sandbox in kali linux
try this it worked for me!
got to the Microsoft store
install vs code form there
then an error massage will appear
now try to open your vs code and wait ...
You can try by searching vs code and if it opens you can right click it, create the shortcut and use it instead of the old shortcut. This worked for me so please try it.
Here is the best solution:
No need to uninstall or do anything.
I was also facing the same issue. Go to task manager. You'll see that visual studio code is running. Select it and press end task. Now you can open vscode normally. It's fixed!
Somehow I had two vs code installs on my computer (one user and one system) and they appeared to be conflicting. I uninstalled user and everything worked. I suggest uninstalling all versions and reinstalling using the system installer executable.
Just reinstall the vs code from previously downloaded setup, everything including extensions get restored. enjoy coding
I Have Got the Same Problem as you just open the folder where you have downloaded VS Code. Like in My case its in Drive C and open from icon in that folder.
you can fix this issue by selecting run this program as administrator under compatibility tab.
If you are on win10, kill all vscode processes, delete folder 'C:\Users\xxx\AppData\Roaming\Code', and launch vscode again.
if anyone is still wondering abt it, Microsoft ended support for Windows 7 in January, 2020 and no longer provides security updates. VS Code desktop versions starting with 1.71 (August 2022) will no longer run on Windows 7 and you will need to upgrade to a newer Windows version to use later versions of VS Code.
Thus, if you want to keep windows 7 version, you have to download an older version than 1.71 of VS Code , for example, 1.69 version (https://www.filepuma.com/download/visual_studio_code_64bit_1.69.1-32681/) and uncheck all the auto updates from the settings.
whenever you want to add any extension, you just have to choose the older version of it.
If you cannot open the vs code editor on windows 7, then you need to download the latest version 1.70.2 from July 2022, which is supported by windows 7. Here is a link as an example: https://update.code.visualstudio.com/1.70.2/win32-x64/stable

Visual Studio Code only compiles when launched from project folder on Linux

I have Visual Studio Code installed in Ubuntu 20.04. I love how it works. I installed it from the tar ball. Same with the SDK. I just found that those appear to work better than installing from deb packages.
I created a desktop file so I could add Visual Studio Code to the dock and launch it that way, but what I've noticed is that projects won't compile. I get errors stating it can't find the project even though the errors are listing the folder where the items exist.
The only way I can get it to work is to:
Open a terminal.
Navigate to the folder where the project files reside.
Launch code from the command line.
Then it works. Otherwise, I get a pop-up error that says "The preLaunchTask 'build' terminated with exit code -2" and then the terminal window is filled with errors.
Here's the last of the error messages and then I opened up a terminal and it shows that I'm in the folder for the project and the csproj exists there:
This also happens if I install Visual Studio code from a repository. It seems launching it from the Unity desktop breaks something. But if I launch it from the command line in a terminal session from the folder where the project resides, then the problem goes away.
I can also reproduce this error from the command line if I launch Visual Studio Code from a different folder than the project I'm trying to compile.
Is this common? Just curious. I'm wondering if because when I launch it from the Unity desktop, it's launching under a different
I got it working under 20.04. I must have done something wrong so I did a wipe of the .NET Core install and reinstalled it all using the bash shell script and then was able to install Code via Software Installer tool. Not sure why it didn't work before, but it works now.

How to open Visual Studio Code from the command line on linux?

I know I can use command "code" to open VS code or file, but I don't know what should I do to make it possible after I install VS code in Ubuntu.Thanks.
Launching from the Command Line
You can launch VS Code from the command line to quickly open a file, folder, or project. Typically, you open VS Code within the context of a folder. We find the best way to do this is to simply type:
code .
Tip: We have instructions for Mac users in our Setup topic that enable you to start VS Code from within a terminal. We add the VS Code executable to the PATH environment variable on Windows and Linux automatically during installation.
Sometimes you will want to open or create a file. If the specified files does not exist, VS Code will create them for you:
code index.html style.css readme.md
Tip: You can have as many file names as you want separated by spaces.
Source: https://code.visualstudio.com/Docs/editor/codebasics
So, there are a couple of solutions for this.
I've linked a video that shows you how to add vscode to $PATH
(which didn't work for me because I couldn't find the "shell:install path" command)
I uninstalled the vscode from my ubuntu and re-installed using sudo snap install --classic code
(This method worked for me)
Tell me which one works for you... and if you have extensions installed to your vscode then i guess you ought to make a backup or something.
Link to the video: https://youtu.be/iP5FKZXtDBs