Code language not supported or defined VS Code Error [Fixed]

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
5 min

banner

# Code language not supported or defined VS Code Error [Fixed]

The "Code language not supported or defined" VS Code error occurs for 3 main reasons:

  1. VS Code isn't able to determine the language of the file you're trying to run.
  2. The file has an incorrect extension.
  3. The language of the file isn't supported by the Code Runner extension.

code language not supported error

# Try setting the language of the file explicitly

VS Code is usually able to guess the type of the file and sets the language automatically.

However, in some rare cases, it can't determine the language of the file.

  1. Click on the Select language mode label in the Status bar at the bottom.

vscode select language mode

The label might be named Plain Text or might be set to a different language.

  1. Select a language from the list. You can also use the search field to filter for a specific language because the list is quite long.

select language from list

By default, the setting is set to Auto Detect and VS Code might not be able to detect what language the file is written in.

Once you set the language, you should get syntax highlighting and you should be able to run the file.

set the language correctly

You can also use the Command Palette to set the language of the file:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type change language and select Change Language Mode.

change language mode

  1. Select a language from the list or use the search field to filter.

select language

# Make sure your file has the correct extension

Another common cause of the error is your file having an incorrect extension.

For example, naming your file main.py.txt prevents VS Code from knowing that the file is a Python file.

The .txt extension at the end marks the file as a text file.

incorrect extension of file

You can rename the file and correct the extension in Explorer (the left sidebar).

Right-click on the file in Explorer and select Rename.

right click rename file

Note that you can also rename the file by selecting it in Explorer and pressing F2.

Correct the extension and press Enter to confirm.

The extensions of files are hidden by default on Windows, so this might be the issue even if your file seemingly has the correct extension.

If you need to show the file extensions on Windows:

  1. Open the folder that contains the file.
  2. Click on View and then tick the File name extensions option.

show file name extensions on windows

Make sure your file has the correct extension and doesn't end in .txt.

# Trying to run a file written in a language that is not supported

Another common cause of the error is trying to run a file that is written in a language that isn't supported by the Code Runner extension.

You can view all of the languages that the Code Runner extension supports by clicking on the following link.

For example, you might be trying to run an HTML file with the Code Runner extension.

trying to run html files

Since the Code Runner extension doesn't support running HTML files, you have 2 options:

  1. Open the file in the browser.
  2. Install an extension that can be used to run HTML files.

You can right-click on the name of the file and select Open containing folder or Reveal in Explorer View.

If you are on macOS, you might also see a Reveal in Finder option.

open containing folder

Once you open the containing folder, double-click on the file to open it in the browser.

Alternatively, you can run the file with the Live Server extension.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux
    • Command + Shift + X on macOS
  1. Type Live Server.

install live server extension

  1. Click on the Install button.

Make sure to install the correct Live Server extension as shown in the screenshot.

Once the extension is installed:

  1. Open the HTML file.
  2. Right-click and select Open with Live Server.

right click select open with live server

You can also use the Command Palette to run the file:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type live server and select Live Server: Open with Live Server.

open with live server command palette

The Live Server extension will run your HTML file and will open a browser tab automatically.

Every time you make changes, the page automatically refreshes and shows the most recent version of your file.

live server extension open html file

# Explicitly setting the command to run a file with a certain extension

If the error persists, you can explicitly set the command that should run when you try to run a file with a certain extension.

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type code runner executor map and under Code-runner: Executor Map By File Extension, click on Edit in settings.json.

executor map by file extension

The settings.json file will open where you can specify what command should run when a file with a certain extension is run.

For example, if you want to run files with .js extension with node, you'd add the following line.

settings.json
".js": "node",

Similarly, if you want to run files with a .py extension with python you'd add the following line.

settings.json
".py": "python",

map extension to command

I've also written an error on how to solve the issue where the Live Server extension doesn't work in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.