question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support passthrough dynamic import, or basic code doesn't work

See original GitHub issue

Please 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:open
  • Created 3 years ago
  • Reactions:5
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
brad4dcommented, Nov 4, 2020

@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:

  1. import(anything) will be left in the source code entirely unmodified.
  2. Specifically, the compiler will not pay any attention at all to the value passed to import(), so it won’t notice if it looks like the path to a file that is included in the compilation.
  3. The compiler will infer the type of all such expressions to be Promise<*>. (You must cast the result of the promise to some type the compiler knows about in order to do anything with it.)
2reactions
AshleyScirracommented, Nov 4, 2020

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:

  1. Fail compilation if feature exists (current state)
  2. Ignore feature/pass through compilation without alteration (what I’m asking for here)
  3. Full support (e.g. potentially taking in to account dead code elimination, bundling, transpilation, tree shaking etc) - as apparently described in issue #2770

I’d have thought passthrough is more or less trivial, whereas full support would involve more significant work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED] - Dynamic import not working - help - Meteor forums
Hey there! I'm trying to implement dynamic loading to split the code per page to minimise the main bundle size cause the app...
Read more >
vue.js - @babel/plugin-syntax-dynamic-import not working in ...
babelrc file, and I am successfully able to use dynamic imports on Vue files that are in my own project, but when trying...
Read more >
Components - Astro Documentation
Components. Astro components are the basic building blocks of any Astro project. They are HTML-only templating components with no client-side runtime.
Read more >
Add a PCI Device to a Virtual Machine - VMware Docs
PCI vSphere Dynamic DirectPath I/O devices ... VMware does not support USB controller passthrough for ESXi hosts that boot from USB devices ...
Read more >
Dynamic imports and preloading in Next.js, doing it the right way
Another cool feature of Next.js is its support for Incremental ... Below's code snippet exemplifies how web asset preloading works in a bare ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found