Version mismatch between tsc compiler and VS Code's language service - visual-studio-code

I just started playing with Visual Studio Code and when I created a new file called index.html, I am shown this warning message
A version mismatch between the globally installed tsc compiler (1.0.3.0) and VS Code's language service (1.8.10) has
Can someone please guide me what i have to do to fix this.
Is this serious or I can ignore. I googled but could not get much info
Thanks

I added this to my settings.json file, accessed through preferences > Workspace Settings :
"typescript.tsdk": "node_modules/typescript/lib"
now I no longer receive this error and in the bottom right corner of my screen it shows the current version of Typescript that I have installed.

[UPDATE] VS Code 1.6 now ships with TypeScript 2.0.3.
I just installed the latest Typescript, currently v.2.0.3, and installed VS Code v.1.5.3 on macOS Sierra. For some reason, exactly following the official doc didn't work for me.
Here's how I made it work:
After having installed the latest version globally:
npm i -g typescript, I added the following line to my settings.json file (opened by cmd + ,):
"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib",
Hope this helps someone else.
[update] as #ptpaterson mentioned on the comment below, on Windows the path is: "typescript.tsdk": "C:/Users/{user_name}/AppData/Roaming/npm/node_modules/typescript/lib/"

You have to change the version of TypeScript that Visual Code is using to match the version you have installed:
https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions
The above is taken from the link:
If you want to use a newer version of TypeScript, you can define the typescript.tsdk setting (File > Preferences > User/Workspace Settings) pointing to a directory containing the TypeScript tsserver.js file.
You can find the installation location using npm list typescript, tsserver.js is usually under the lib folder.
For example:
{
"typescript.tsdk": "node_modules/typescript/lib"
}

You have to update your Typescript installation and restart Code afterwards:
npm install -g typescript
or
npm install -g typescript#1.8.10
The message should not longer appear, if it worked.

This error was being generated because I had a reference to an older installation of TypeScript in my System Path variable:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
The Visual Studio Code error was resolved when I removed this entry.
However, my TypeScript files then failed to transpile as the build action couldn't find the tsc.exe file.
When the SDK is installed (through Visual Studio or via a manual *.visx install), a tsc.exe file is installed and the PATH environment variable is updated to reference the folder that this file resides in (see above).
There is another way to transpile your files on a Windows environment by using node.js:
Install node.js. Installation packages can be found here.
Use npm to install TypeScript:
npm install -g typescript
This will add the TypeScript files to your profile AppData folder:
C:\Users\{your_user_name}\AppData\Roaming\npm\node_modules\typescript\lib
Configure your Visual Studio Code user settings.json file to reference this folder:
{
"typescript.tsdk": "C:\\Users\\{your_user_name}\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"
}
Add / update the user PATH environment variable to reference the folder that contains the tsc.cmd file:
%USERPROFILE%\AppData\Roaming\npm

None of the solutions above worked for me - first of all this is the global tsc I want to have updated to the latest version.
After I did some investigation it turned out that the problem lies in system's PATH variables; tsc.cmd (along with tscserver.cmd) exists in these locations:
c:\Program Files\nodejs - where the npm.exe and node.exe are
%USERPROFILE%\AppData\Roaming\npm - where global packages are
What you can do is to juggle environment\user variables so the tsc command would be resolved from %USERPROFILE% first instead of Program Files.
The quick & dirty way would be just deleting tsc.cmd and tscserver.cmd from the Program Files path.

Installing v2.0.3 of typescript was not sufficient... but but then updating the version dependency on package.json worked for me.
Npm command:
npm install -g typescript#2.0.3
Updated line on package.json:
"typescript": "^2.0.3"

The cause of my experience with this issue (in VSCode 1.8 on Mac OS X 10.12.2) was that I have been using NVM and while my code was running on the NVM version, VSCode was looking at a system installation of node.
Double check which installation of npm you are using to install typescript globally. If in doubt (on linux/mac) use which tsc from the command-line to verify the location being used by VSCode.
For example, if I simply call npm i -g typescript, npm resolves to ~/.nvm/versions/node/v6.9.1/bin/npm. I had to solve the problem by calling /usr/local/bin/npm i -g typescript explicitly because VSCode looks for node in /usr/local/bin/node by default.

Install TypeScript globally to share the installation across workspaces. In this case, you install it using npm install -g typescript#next.
You then have to tell VS Code on setting.json file (File -> Preferences -> Workspace Settings) the install location using the typescript.tsdk setting. Set typescript.tsdk to the path of the lib folder containing the tsserver.js file of the installed TypeScript module.
On windows:
"typescript.tsdk": "C:/Users/<MyUser>/AppData/Roaming/npm/node_modules/typescript/lib"
On Mac:
"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib"

Installing VSCode 1.6.0 fixed the TypeScript version mismatch warning message for me.

You'd think that this being a Microsoft product they'd give the Windows paths on their website
https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions
but they don't. They only give the Unix path types.
Use:-
On windows: "typescript.tsdk": "C:/Users/YourNameHere/AppData/Roaming/npm/node_modules/typescript/lib/"
Note that forward strokes must be used even though Windows uses backstrokes for the paths!
Some other answers miss off the last forward stroke which is necessary.

You can just remove 'typescript.tsdk' and use the one embedded in Code if you don't really care about which tsdk version you use.

Related

rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found

I have Rust installed using WSL2 Ubuntu I have alredy ran basic commands like hello world in rust so cargo is working. I wanted to download the rust-analyzer in VSCODE but I keep getting that error message from the title: rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found
I tried ensuring all paths are correct, all vesions of extension and vscode and rust are up to date. several uninstall re-installs and rustup updates. Toolchain is using stable version. I have reviewed a lot of the other post about this accross all platforms but it seems I can not find the fix. It would be very helpful to get some guidance. Thank you!st
The solution is to open folder as if in WSL.
To do that you need to install this VS code extension called Remote development
Than go to the green symbol in the bottom right corner and then select open WSL folder and open folder with your rust project or just open new WSL window
The last step is to go to extensions and then search for rust-analyzer and hit install
More info regarding the development on WSL can be found here
another good option is open your wsl, move to the project folder and type $ code . or $ code YOUR_PROJECT, then install rust-analyzer extension
Remove the rustc and cargo provide by system package manager (e.g. apt).
Install them from offical rustup script instead.
[note]
I just encounter the same problem when using flatpak version of Lapce.
rust-analyzer failed to load workspace: "cargo" "--version" failed: No such file or directory (os error 2)

Is it possible to specify the path to the libstdc++ in VS Code clangd extension?

I use VS Code as my main code editor for my C++ development. I am using the remote SSH extension by Microsoft to access my office workstation from home. For the C++ autocompletion and linting I use the clangd extension by LLVM. Company policy prevents users from having sudo access to workstations and libraries are often not at the latest version.
When I try to launch clangd I get the following error message:
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /my/path/to/clangd)
Which obviously means that the version of libstdc++ is too old for the version of clangd that I am using. This is easily fixable by adding to LD_LIBRARY_PATH the location of most recent gcc libraries (part of our compiler toolchain) and then launching VS Code.
However, now that I am working remotely I cannot do that because VS Code is installed onto my laptop and I am using the SSH extension to access the code on my office workstation. Looking on the man page for clangd I cannot see a way to specify the path to the libstdc++ that I want to use. Is there a way, other than adding the libraries to the LD_LIBRARY_PATH upon startup/login, to bypass this issue?
I found a way, albeit a little bit hacky.
Export the new LD_LIBRARY_PATH on .zprofile (or equivalent for your shell. I am using zsh). Make sure that there are no VSCode servers running in the host. If there are, make sure to remove them.
In the settings.json file add the following line, to tell VSCode that you want the shell to be a login, interactive shell:
"terminal.integrated.shellArgs.linux": ["-l", "-i"]
Job done. Clangd now finds the correct libraries.
Another way to do this is to use env in your settings.json as follows:
"clangd.path": "env",
"clangd.arguments": [
"LD_LIBRARY_PATH=<your_custom_path>",
"/path/to/my/clangd"
],

Couldn't start client Rust Language Server

I'm trying to figure out how to use rustc & cargo from my WSL. I use VS Code and Rust (rls) plugin and can compile my code but there is a problem with RLS:
Couldn't start client Rust Language Server
Rustup not available. Install from https://www.rustup.rs/
How i can solve this problem?
Set rust-client.rustupPath in VSCode settings:
{
"rust-client.rustupPath": "~/.cargo/bin/rustup"
}
If you're using WSL on Windows then make sure you edit Rust extension WSL settings, not user/local settings.
Tutorial:
I had this problem as well with WSL and Visual Studio Code. The problem seems to stem from the fact that the Rust Language Server needs to find rustup in your path. We both probably followed the same path of using a package manager to install cargo, and therefore, the rust compiler tools. This does not include rustup which you can actually use to keep the rust toolchain up-to-date. rustup also appears to be the preferred method of installing the rust toolchain on your system.
After installing rustup with the default setup, you should see a .rustup directory in your home directory. This is where the toolchain lives. The install text all stated that it would add the toolchain to your environment path after logging out and back in, but I didn't have luck with this. I'm currently using fish instead of bash and had to update the configuration to include the toolchain at startup. Once I did that, I was able to have VSCode properly install and run the RLS.
This worked for me for in a remote SSH environment with Ubuntu 20.04
Edit .profile and .bashrc files in the user home directory
In .profile, comment the following line:
export PATH="$HOME/.cargo/bin:$PATH"
In both, add the following line:
[[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]] && PATH="$HOME/.cargo/bin:${PATH}"
Reboot.
Even though if I run:
which rustup
/Users/justincalleja/.cargo/bin/rustup
A simple entry of rustup in the VSCode settings for:
"Rust-client: Rustup Path Path to rustup executable. Ignored if rustup
is disabled."
wasn't enough and I had to put the absolute path to the rustup binary as shown above. After doing so, I reloaded the window and was then asked to download missing components (or dependencies - the prompt is gone now I forgot). After doing this, the VSCode plugin seems to be working fine. I can format the code at least.
So it looks like it's some mismatch with VSCode's PATH and the PATH on my system. I'm not sure what it is but if you just want to get the extension to work, try using the absolute path to rustup in your Settings.
(Note: source "$HOME/.cargo/env" is added automatically to your startup files like .bashrc. First thing I tried was adding it to the startup file of zsh; the shell I'm using and to which it wasn't added. But that doesn't work either. I'm using rustc 1.49.0 (e1884a8e3 2020-12-29) ).
So... I'm running Rust on Windows 10 and I experienced this same issue. My Rust version is 1.24.3, my VSCode version is 1.63.2.
The first thing you need to do is add "%USERPROFILE%.cargo\bin" to your environment variables
The next solution that worked for me can be found in this tutorial: Rust on Windows and Visual Studio Code
i am running VSCode on mac, and using remote development.the remote server is
ubuntu 20. i had this problem, added rust-client.rustupPath to vscode settings and killed the vscode-server on remote server to fix this problem. now it work.

Visual Studio Code "Could not install typings files for JavaScript ..."

I'm new to node.js and am trying to learn it with Visual Studio Code as my editor (1.13.1).
With my .js file open I see:
Could not install typings files for JavaScript language features. Please ensure that NPM is installed or configure 'typescript.npm' in your user settings
I do have npm installed:
C:\>npm --help
Usage: npm <command>
How can I fix the message?
I could add 'typescript.npm' in my user settings but I don't know what value to give it. Please can anyone give an example?
It looks like there is an explanation for your case. So it should be the full path of the npm.
In my case this is C:\Program Files\nodejs\npm.cmd.
The other solution is starting VS Code by administrator privilege.

"No extensions found" when running Visual Studio Code from source

When I try to install any extension in Visual Studio Code (i.e., by pressing Ctrl+P and then running ext install RustyCode), I get a message that No extensions found.
However, this only happens when I run VS Code directly from source repository. I.e., after:
git clone https://github.com/Microsoft/vscode.git
cd vscode
git checkout 1.0.0
scripts/code.sh
But, if I run VS Code from official builds, then I'm able to install extensions.
So, how can I enable downloading and installing extensions from Visual Studio Marketplace when I run VS Code directly from source repository? (Is Visual Studio Marketplace integration bundled separately in official builds?)
I'm on Ubuntu/Linux.
This can be fixed by adding following to product.json:
"extensionsGallery": {
"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
"cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
"itemUrl": "https://marketplace.visualstudio.com/items"
}
(This is can also be fixed by copying product.json from an official build (in the .zip archvie, product.json is under resources/app) which contains above lines).
More information: https://github.com/Microsoft/vscode/issues/1557
You can use code-marketplace extension in AUR to add microsoft marketplace registery in code OSS. This extension will installs a pacman hook that patches the file on every package update.
If you want to do the same for archlinux, have a look here => https://wiki.archlinux.org/index.php/Visual_Studio_Code , you have various possible options to solve the problem.
For Arch linux you could access the product.json file under this path - /usr/lib/code/product.json.
Just edit on the file the extensionsGallery with the following-
"extensionsGallery": {
"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
"cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
"itemUrl": "https://marketplace.visualstudio.com/items"
}
like #Vikrant Chaudhary said.
Extending the answer from #Vikrant Chaudhary. If anyone wanted to do the same thing on Windows, the path to product.json is here:
Windows path for VSCodium: C:\Program Files\VSCodium\resources\app\product.json