denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.37k stars 5.36k forks source link

Import maps (from deno.json > "imports") don't work in VS Code #25631

Closed cristian-spiescu closed 1 month ago

cristian-spiescu commented 1 month ago

Version: Deno 1.41.2

It's only after the standard lib moved to JSR that I found out about the deno add command, and the "import maps" feature. Leveraging this, deno.json > imports is somehow the equivalent of package.json > dependencies.

Before this, I was thinking that the pattern of deps.ts is the equivalent of package.json > dependencies.

However, I observe that in my case, VS Code doesn't recognize deno.json > imports. I.e., I have this:

image

But the IDE complains about this:

image

The program executes successfully. So Deno itself did recognize the import.

I tried various combination of settings.json:

image

I also inspected Output > Deno Language Server, but nothing seemed suspect.

Searching the Internet didn't gave much results. https://github.com/denoland/deno/issues/20210 seems a bit related, but the context there (i.e. a deno.json being in a subdir of the project) is not similar to mine.

dsherret commented 1 month ago

1.41.2

Is it fixed in the latest Deno version?

maxxmberry commented 1 month ago

Deno Version: 1.46.3

I'm getting another error but also possibly because of JSR. I'm trying to import parseArgs from the @std/cli package to my file, but I'm getting an error for an uncached or missing remote URL.

I added @std/cli into the import map like usual, but when I write import { parseArgs } from "@std/cli";, the error appears. deno-issue-screenshot

I don't know if this issue is related to yours, but I thought I'd reach out.

BlackAsLight commented 1 month ago

I'm trying to import parseArgs from the @std/cli package to my file, but I'm getting an error for an uncached or missing remote URL.

Click the Quick Fix... button that appears in the image and click the cache dependency option. The error is saying that it doesn't have that dependency stored locally on the device so it is having trouble giving you information about it. Running the program once will also cache any missing dependencies, but I believe you can also do deno cache <file> and it will cache any missing dependencies imported in said file.

maxxmberry commented 1 month ago

Running the program once will also cache any missing dependencies

Thank you for the help. I'm somewhat new to TS/Deno and coding in VS Code, so I didn't know running the program would help the issue. Thanks again!

cristian-spiescu commented 1 month ago

You have closed the issue. Unfortunately I still have the problem. Some hints would be appreciated. Thanks.

kt3k commented 1 month ago

@cristian-spiescu What happens if you upgrade Deno to the latest (1.46.3)?

lucacasonato commented 1 month ago

@cristian-spiescu is the .vscode folder in the root directory of your vscode project?