Last updated: Apr 6, 2024
Reading time·5 min
The following two VS Code errors occur for the same reasons:
The most common causes are:
settings.json
file. Instead, you should edit
the global user settings.json
file.To solve the errors in VS Code:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
Make sure to check the Code-runner: Run in terminal checkbox as shown in the code sample.
Alternatively, you can enable the setting directly in your settings.json file.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
settings.json
file.{ "code-runner.runInTerminal": true }
Either approach works.
After you set the setting, restart VS Code:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Try to run your code after having enabled the setting.
You can click on the arrow in the top right corner to run your code in the terminal.
You can also right-click in the editor window and select Run Code.
You can also use the Command Palette:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.If your code is stuck in the Output tab, right-click and select Stop Code Run.
You can also stop the Code Runner process by using a keyboard shortcut:
Ctrl
+ Alt
+ M
on Windows and Linux.Cmd
+ Option
+ M
on macOS.If the error persists, you might have a VS Code process that runs in the background.
On Windows, open CMD and run the following command to stop all VS Code processes.
# Windows taskkill /F /IM code.exe
On macOS and Linux, run the following command to stop all VS Code processes.
# macOS and Linux killall code
If the killall
command doesn't succeed on macOS or Linux, try issuing the
following command instead.
ps -ef | grep code | awk {'print $2'} | xargs kill -9
Once you run the command and stop all VS Code processes, restart the IDE and try to run your code.
Note that when you click on the x
icon at the top right corner of the
terminal, you don't actually close it.
If you click on the x
icon, the terminal still runs in the background.
You need to click on the trash bin icon to close it and stop the process.
settings.json
fileYou can't edit the default settings.json
file because it is in read-only mode.
Instead, you should open the global user's settings.json
file which is
editable.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
Now you can edit the non-default version of the settings.json
file.
If you want to read more about the different ways to open and edit
settings.json
, check out my other article:
If you clicked on the source control icon in the Activity bar on the left, you most likely opened a git diff split screen.
The left side of the screen is the previous version of the file, so you aren't able to edit it.
To resolve the issue, click on the explorer icon at the top of the Activity bar and open the file in editable mode.
You shouldn't see two versions of the file in a split screen once you open it in editable mode.
If the error persists, try to disable your extensions.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Type disable extensions and select Extensions: Disable all installed extensions.
Check if you can edit the file.
If you can edit the file after disabling all installed extensions, try to enable them one by one to see which extension caused the issue.
I've also written an error on how to solve the issue where the Live Server extension doesn't work in VS Code.
You can learn more about the related topics by checking out the following tutorials: