Dynamic imports is a decent feature for what it is capable of, however, it currently seems to lack the ability to load dynamic URLs. As an example, we cannot import a module from the current working directory in CLI tools:
import(`${Deno.cwd()}/some_file.ts`).then(console.log);
For regular dynamic imports of relative modules, a similar approach with a static string representing a module in a relative directory works:
import("./relative.ts").then(console.log);
Is there something I'm missing?
Dynamic imports is a decent feature for what it is capable of, however, it currently seems to lack the ability to load dynamic URLs.
What error are you getting?
thread 'main' panicked at 'internal error: entered unreachable code', cli\state.rs:452:12
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@undefinedbuddy This one, I assume? Looks like on Windows it interprets the drive letter as the protocol, whereas on unix it just gets a regular looking absolute path and that works.
@kitsonk Like @nayeemrmn mentioned.
How do I fix this issue in a cross-platform way?
@undefinedbuddy It's an internal bug. You can prepend file:/// to the import specifier for now, seems like it works.
Great! Does it work for all platforms? Can I simply use:
import(`file:///${Deno.cwd()}/some_file.ts`).then(console.log);
On Windows, this would most likely concatenate it with the drive letter as file:///C:\.
/ actually feels like a side effect.@undefinedbuddy technically you need to change the \ to / in URIs (https://en.wikipedia.org/wiki/File_URI_scheme#Windows_2). I believe there are some functions in std/path/mod.ts that help with all of this.
Alright, I'll certainly give that a shot!