hewlothereH
Deno•15mo ago
hewlothere

Type resolution for modules imported with `npm:` specifier

moved from here: https://discord.com/channels/684898665143206084/684898665151594506/1292948811643224136

if i'm importing something from npm with an
npm:
specifier (i.e. npm:vite), if it has type definitions that reference another npm package (i.e. esbuild), is it a deno issue or a package issue if the types aren't resolved by deno (at least, the deno vscode extension)?

tried with both npm:vite@5.4.8 as well as npm:vite@6.0.0-beta.2 and both of them don't load the types of esbuild when importing.

i don't have this issue when importing it from esm.sh, though. and if i manually add esbuild to the imports in my
deno.json
, it works too. but not if i directly import from npm:vite.

if this is to be expected then that's all good, just was wondering if i should report an issue or anything 🙂

actually, it correctly resolves the type (in the vscode extension?) up until i try to look at the types for vite.

not sure if it's just flaky, but it seems to only work (until i navigate to the types for vite) if i tell deno to generate a lock file and i have run deno clean? i think?
e.g.:
deno.json
:
{
  "lock": true,
  "imports": {
      "vite": "npm:vite@^6.0.0-beta.2",
      "esbuild": "npm:esbuild@^0.24.0",
      "postcss": "npm:postcss@^8.4.47",
      "rollup": "npm:rollup@^4.22.5"
  }
}

file.ts
import { build } from 'vite';

await build({
  // stuff
  esbuild: {
    loader: 'tsx', // error is here, but only after i try to look at the types for vite in vscode.
  },
});
Was this page helpful?