Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import.meta.resolve with npm specifiers inconsistency #27436

Open
oscarotero opened this issue Dec 20, 2024 · 0 comments
Open

import.meta.resolve with npm specifiers inconsistency #27436

oscarotero opened this issue Dec 20, 2024 · 0 comments

Comments

@oscarotero
Copy link
Contributor

oscarotero commented Dec 20, 2024

Version: Deno 1.44.1 and greater (including Deno 2)

I just realized npm specifiers have changed its behavior with import.meta.resolve in Deno 1.44.1 and this breaks the esbuild plugin of Deno in some cases (like in this example).

For example, let's say I have the following import map:

{
  "imports": {
    "react": "npm:[email protected]"
  }
}

In Deno 1.44.0:

import.meta.resolve("react"); // npm:[email protected]
import.meta.resolve("npm:[email protected]"); // npm:[email protected]
import.meta.resolve("npm:[email protected]"); // npm:[email protected]

In Deno 1.44.1 or Deno 2:

import.meta.resolve("react"); // file:///Users/oscarotero/Library/Caches/deno/npm/registry.npmjs.org/react/18.3.1/index.js
import.meta.resolve("npm:[email protected]"); // npm:[email protected]
import.meta.resolve("npm:[email protected]"); // file:///Users/oscarotero/Library/Caches/deno/npm/registry.npmjs.org/react/18.3.1/index.js

As you can see, sometimes the resolver returns the file URL to the local cache file, some times it returns the npm specifier.

Is this the expected behavior? Is there any way to make it work like before? I want to detect if a bare import (like react) is pointing to a npm specifier or not. I don't want the local cache file.

@oscarotero oscarotero changed the title import.meta.resolve with npm specifiers import.meta.resolve with npm specifiers inconsistency Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant