denoland / deno

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

deno-ls: `Uncached or missing npm package` when using `node:` specifier #23350

Open Sleepful opened 4 months ago

Sleepful commented 4 months ago

Version: deno 1.42.3 (release, aarch64-apple-darwin

// @deno-types="npm:@types/node@^20.12.7"
import * as path from "node:path";

This gives an LSP diagnostic message (red squigglies) on the import line that says

Uncached or missing npm package: @types/node@^20.12.7

The same message(minus version number) is shown if I remove the deno-types hint.

As a side effect, the same diagnostic gets repeated for all the npm: imports in the file (even though they don't have this issue if the node:path is removed)

E.g.

import { readFileSync } from "node:fs";     ■■■ Uncached or missing npm package: @types/node
import { type GeneratedAlways, Kysely, sql } from "npm:kysely";     ■ Uncached or missing npm package: kysely
import { PostgresJSDialect } from "npm:kysely-postgres-js";     ■ Uncached or missing npm package: kysely-postgres
lucacasonato commented 2 months ago

Does the error persist if you run > Deno: Cache from the VS Code command palette when you see that error?

Sleepful commented 2 months ago

@lucacasonato is there a CLI equivalent? I am not in VS Code. I will test again.

lucacasonato commented 2 months ago

deno cache main.ts

lucacasonato commented 2 months ago

Closing as there has been no response from OP. Please re-open if still an issue.

Sleepful commented 2 months ago

@lucacasonato ohai, the deno cache main.ts does not help with the node:fs package. At least not in my computer.

try it yourself, mkdir test && cd test && deno init

Then put this in your main.ts

import { readFileSync } from "node:fs";

export function add(a: number, b: number): number {
  return a + b;
}

// Learn more at https://deno.land/manual/examples/module_metadata#concepts
if (import.meta.main) {
  console.log("Add 2 + 3 =", add(2, 3));
}

It should give you the diagnostic on the first line

Sleepful commented 2 months ago

I believe I cannot re-open the issue btw!