Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid the "an import path cannot end with .ts extension" error in VSCode?

I'm using Visual Studio Code to write Deno programs.

The import statement in Deno contains the .ts extension, e.g.

import { Application } from "https://deno.land/x/oak/mod.ts";

which is marked as a problem in VS-Code, error code ts(2691):

enter image description here

Despite the shown error, the program works fine, but I want to avoid the error message, because there's nothing wrong.

How can this be solved?

like image 624
jps Avatar asked Dec 02 '20 20:12

jps


People also ask

How do I fix imports in VSCode?

Set the correct Python path in VSCode In order to fix Unresolved Import in VSCode, you have to set python. pythonPath key in the settings to the correct value. You can quickly open the settings. json editor by accessing File > Preferences or press Ctrl + , key combination.

How do I rename a Visual Studio code?

Renaming is a common operation related to refactoring source code and VS Code has a separate Rename Symbol command (F2). Some languages support rename symbol across files. Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.


1 Answers

This can be solved by installing and configuring the Deno Extensions for VSCode.

Press CtrlShiftX to open the extensions view, then type "deno" and click on the entry name "Deno - Deno support for VSCode":

enter image description here

and install it.

After installation, you can choose any one of following methods:

  • Go to settings: (Ctrl, or Cmd, on MacOSX), select "Extensions>Deno" and click on the checkbox under "Deno:Enable" and "Deno:lint"
    • Just enable workspace settings only
    • Don't enable User settings if you have other Non node projects

enter image description here enter image description here

  • Or, as @hong4rc mentioned, open the Command Palette(Ctrl+Shift+P) and select Deno:initialize

Either method creates a folder named .vscode and a file settings.json with the following lines in your workspace project ( workspace settings):

{
  "deno.enable": true,
  "deno.lint": true
}

In both cases, after restarting Visual Studio Code, the error should be gone.

like image 57
jps Avatar answered Oct 16 '22 20:10

jps