Support passthrough dynamic import, or basic code doesn't work
See original GitHub issuePlease at least support a basic passthrough for dynamic import for Closure Compiler. In the current version, any presence of dynamic import at all causes a compilation failure. This causes even basic use cases of dynamic import to cause the entire compilation to fail.
Example in.js:
(async () =>
{
await import("https://cdn.example.com/library.js");
externalLibrary.someFunc();
})();
Command line:
java -jar ./closure-compiler.jar --js in.js --js_output_file out.js --compilation_level SIMPLE --formatting PRETTY_PRINT --language_in ECMASCRIPT_2020 --language_out ECMASCRIPT_2020
Observed result:
in.js:4:7: WARNING - [JSC_PARSE_ERROR] Parse error. This language feature is not currently supported by the compiler: Dynamic module import
4| await import("https://cdn.example.com/library.js");
^
ERROR - [JSC_FEATURES_NOT_SUPPORTED_BY_PASS] Attempted to run pass "markUntranspilableFeaturesAsRemoved" on input with features it does not support. Running pass anyway.
Unsupported features: [Dynamic module import]
1 error(s), 1 warning(s)
No output file is generated.
Expected result:
Just output the file with all transforms, but passthrough import(XYZ)
-> import(XYZ)
This is blocking us using JavaScript modules at all in our code. We want to insert a dynamic import, but then Closure Compiler will refuse to process any of our code at all.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:14 (5 by maintainers)
Top GitHub Comments
@AshleyScirra do you feel this issue would be completely closed by the following behavior?
If the compiler’s output is set to at least
ES_2020
, then:import(anything)
will be left in the source code entirely unmodified.import()
, so it won’t notice if it looks like the path to a file that is included in the compilation.Promise<*>
. (You must cast the result of the promise to some type the compiler knows about in order to do anything with it.)I think #2770 is asking for full support. I’m only asking here for Closure Compiler not to fail compilation due to the presence of dynamic import, i.e. the minimum possible support. I think there’s basically three levels of support:
I’d have thought passthrough is more or less trivial, whereas full support would involve more significant work.