deno
deno copied to clipboard
Support sloppy imports in `deno compile`
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
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.
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
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