denoland / deno

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

`npm:` import does not resolve type correctly #24321

Open uga-rosa opened 6 days ago

uga-rosa commented 6 days ago

Version: Deno 1.44.1

Summary

I want to use parse() of @babel/parser

https://babeljs.io/docs/babel-parser#babelparserparsecode-options

import { parse } from "npm:@babel/parser";

const ast = parse("const foo = {};");
console.log(ast);

image

Cause

Referring to the type definition of parse(). The reason is that this @babel/types cannot be resolved.

import * as _babel_types from '@babel/types';

// ...

declare function parse(
  input: string,
  options?: ParserOptions
): ParseResult<_babel_types.File>;

Workaround

You can use import map to replace @babel with npm:@babel so that you can trace it.

image

However, in my actual application, I use Worker, so this workaround doesn't work, because import map doesn't work.

ryoppippi commented 5 days ago

I tested with arktype, and got the same result

import { type } from "npm:arktype";

const user = type({
  name: "string",
});

Screenshot 2024-06-24 at 13 07 20