Issue creating a UMD module that uses dynamic import
See original GitHub issueBug 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:
- Created 4 years ago
- Reactions:2
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
Yes I confirmed this is still an issue. I updated webpack to the latest stable (4.43.0) and this still occurs.
Fixed in v5, anyway you need to specify
target: 'node'ortarget: 'web'right now, because logic is different, ideal you need https://github.com/webpack/webpack/issues/6525 (you can track that issue)