denoland / deno

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

Cannot publish jsr package using `bun:`-import specifier, error: invalidexternalimport #26989

Open Hexagon opened 17 hours ago

Hexagon commented 17 hours ago

Version: Deno 1 , 2 and 2.1

Long running issue... I'm trying to publish @cross/test to jsr. This library does a conditional import of bun:test if running Bun, and this error pops up while trying to publish - https://jsr.io/docs/troubleshooting#invalidexternalimport

The code is dynamically imported, so it would never execute in Deno

} else if (CurrentRuntime == Runtime.Bun) {
  const { wrappedTest } = await import("./shims/bun.ts");

... and the actual problem is in ./shims/bun.ts (which again is conditionally imported):

import { test } from "bun:test";
// ...

I originally posted this in as an issue in jsr-io/jsr (https://github.com/jsr-io/jsr/issues/599) , but have figured out that the problem may live in Deno itself:

An outdated error message (as bun-specifiers should be supported by now):

https://github.com/denoland/deno/blob/dd8cbf5e29d9949e3adac9b9d8ce5fb73b5b0ad0/cli/tools/registry/diagnostics.rs#L479

And a function potentially missing a case for bun::

https://github.com/denoland/deno/blob/dd8cbf5e29d9949e3adac9b9d8ce5fb73b5b0ad0/cli/tools/registry/graph.rs#L35

bartlomieju commented 17 hours ago

It appears that this would be solved by https://github.com/denoland/deno/pull/24588, but not sure if that PR is landable.

nathanwhit commented 16 hours ago

Seems like it could be landed if someone picks it up, just needs to be rebased and CI failures fixed