denoland / deno

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

bug: `deno compile` creates a binary that cannot find its HTTP import dependencies #26583

Open KnorpelSenf opened 2 hours ago

KnorpelSenf commented 2 hours ago

Version: Deno 2.0.3

Repro

Create any script with an HTTP import, such as this one:

// /tmp/main.ts
import { Bot } from "https://deno.land/x/grammy/mod.ts";

const bot = new Bot("secret-token");
console.log(bot.token);

Compile it and run the binary.

# /tmp/repro.sh
set -e
deno install --reload --allow-import --entrypoint /tmp/main.ts
deno compile -Ao /tmp/app /tmp/main.ts
/tmp/app

You will see the following output.

error: Module not found: https://deno.land/x/grammy/bot.ts

Instead, it is expected that the script runs correctly and that the output is just secret-token.

Cause

This works correctly with 2.0.2.

I used git bisect to narrow it down to #26494. /cc @dsherret

KnorpelSenf commented 2 hours ago

Note that https://deno.land/x/grammy/mod.ts re-exports Bot (src) so my guess is that the binary only contains the modules that are imported directly, but not those that get imported transitively.

dsherret commented 2 hours ago

I think it’s missing redirects. If you import the resolved specifier it will probably work.

KnorpelSenf commented 2 hours ago

I think it’s missing redirects. If you import the resolved specifier it will probably work.

Can confirm that this fixed it.