deno icon indicating copy to clipboard operation
deno copied to clipboard

Support sloppy imports in `deno compile`

Open thoriqadillah opened this issue 1 year ago • 3 comments

Version: Deno 2.0.0 I tried to play around with deno 2.0 by compiling my nest js project with deno. I thought maybe if i can compile the project into one executable binary that would be cool. Its pretty complex project. But i found that deno cannot compile if my import has no .ts on it. Maybe its obvious, but that would take a tedious task to add .ts in almost every imports

this is the error message

deno compile -R src/main.ts --unstable-sloppy-imports
error: Module not found "file:///project-dir/src/sentry". Maybe add a '.ts' extension or run with --unstable-sloppy-imports
    at file:///project-dir/src/main.ts:1:8

thoriqadillah avatar Oct 10 '24 09:10 thoriqadillah

You need to put --unstable-sloppy-imports after the -R flag. Currently this flag is forwarded to src/main.ts as a value of Deno.args.

bartlomieju avatar Oct 10 '24 09:10 bartlomieju

still cannot compile

deno compile -R --unstable-sloppy-imports ./src/main.ts 
Warning Sloppy imports are not supported in deno compile. The compiled executable may encounter runtime errors.
error: Relative import path "src/modules/broadcast/broadcast.store" not prefixed with / or ./ or ../
    at file:///project-dir/src/lib/notification/notifier/index.ts:4:32

apparently deno also cannot read alias as well, i.e @src/foo. but, in my project (i think this is built in from nest js as well if I'm not mistaken), the alias is just src, so when i import it with alias it would be like this

lets say I'm in src/lib/notification, i will import something from lib directory

import { Baz } from "src/lib/foo/bar";

and deno thought src is a relative path instead of alias

thoriqadillah avatar Oct 10 '24 10:10 thoriqadillah

Yeah, as the warning states, sloppy imports aren't yet supported in deno compile.

that would take a tedious task to add .ts in almost every imports

deno lint --unstable-sloppy-imports --fix automatically adds the extensions

dsherret avatar Oct 10 '24 10:10 dsherret