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.

Issue creating a UMD module that uses dynamic import

See original GitHub issue

Bug report

What is the current behavior?

I’m trying to generate a UMD module that uses the import() syntax. That said, with the current version of Webpack, import() is converted into using document.createElement('script') which causes issues where document is not defined.

If the current behavior is a bug, please provide the steps to reproduce.

Here’s a reproduction of this issue: https://github.com/lannonbr/webpack-umd-dyn-import

What is the expected behavior?

Hoping to eventually have a way so if you do a dynamic import in a UMD module, it will work in both Node and the browser seamlessly.

(For further context, this eventually will be wanted so if I use wasm-pack-plugin, I can dynamically import the WASM bootstrapping code. With that case, as WASM has to be dynamically imported, I cannot transpile import() with something like Babel.)

Other relevant information: webpack version: 4.43.0 Node.js version: 12.16.3 Operating System: MacOS, Ubuntu Additional tools:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
lannonbrcommented, May 6, 2020

Yes I confirmed this is still an issue. I updated webpack to the latest stable (4.43.0) and this still occurs.

0reactions
alexander-akaitcommented, Feb 10, 2021

Fixed in v5, anyway you need to specify target: 'node' or target: 'web' right now, because logic is different, ideal you need https://github.com/webpack/webpack/issues/6525 (you can track that issue)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack UMD library with dynamic imports produces a ...
I'm writing a UMD library with webpack and when I try to import it in another project (for testing), it produces a "ChunkLoadError"....
Read more >
Dynamic imports are only supported when the 'module' flag is ...
To solve the error "Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext' or 'commonjs'", set the module...
Read more >
Need help using ember-auto-import dynamic import
I'm using dynamic import for perhaps the first time and finding myself in the deep end of the build pool. We are generating...
Read more >
import() - JavaScript - MDN Web Docs - Mozilla
Dynamic imports allow any expression as the module specifier, not necessarily string literals. Here, we load 10 modules, /modules/module-0.js , ...
Read more >
Build Options - Vite
Note: the polyfill does not apply to Library Mode. If you need to support browsers without native dynamic import, you should probably avoid...
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