benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
43 stars 8 forks source link

Genes.dynamicImport() needs to include .js extension in emitted JS import() call #65

Closed joshtynjala closed 2 years ago

joshtynjala commented 2 years ago

In web browsers, import("./com/example/MyClass") without the file's extension doesn't work. Tested in Safari, Firefox, and Chrome. None of them like it. They expect the file extension, like import("./com/example/MyClass.js"). Interestingly, it seems that bundlers like Webpack can handle the omitted file extension, so maybe the Genes.dynamicImport() feature was originally tested with an intermediate bundler step, and not directly in a web browser. Or maybe web browsers have gotten more strict over time.

Note: Like static imports, I made it skip the .js extension in dynamic import() calls when genes.no-extension is defined.

benmerckx commented 2 years ago

Thanks, this is an issue indeed. I've implemented this in 5dedb102b11b83e0309b25ab5ffaa5717b92956e to use the extension of the file we're generating to (eg a node library might want to use ".mjs" with -js outfile.mjs).

joshtynjala commented 2 years ago

Thanks!