import()ed module is not executed until .then() or .catch() is called on it
See original GitHub issue// globalHaCKS.js
window.document.stateOverride13 = 'YOLO';
renderLegacyApp();
// just_make_it_less_slow.js
import('./globalHaCKS.js'); // Doesn't work!
import('./globalHaCKS.js').then(); // Works :s
When using webpack’s built in support for the import()
statement, the imported module is executed as soon as the promise is created and the chunk is downloaded. With this package, it seems that the imported module is executed only when .then()
or .catch()
is called on the promise (even though either way the chunk is downloaded as soon as the promise is created).
This seems like an unnecessary and confusing breaking change compared to the way import()
works in webpack. Any chance of changing it so that it is not necessary to call .then()
or .catch()
on the promise?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
loadable not working in SSR with webpack module federation
To capture it during runtime and not compile time, we can proxy import's thenable. When 'then' is called, we add the chunk to...
Read more >Understanding the Event Loop, Callbacks, Promises, and ...
The event loop checks the queue for any pending messages and finds the anonymous function from setTimeout() , adds the function to the...
Read more >Dynamic imports - The Modern JavaScript Tutorial
The import() expression The import(module) expression loads the module and returns a promise that resolves into a module object that contains ...
Read more >8. Errors and Exceptions — Python 3.11.1 documentation
Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon learn how to handle them in Python programs....
Read more >async function - JavaScript - MDN Web Docs - Mozilla
async function asyncCall() { ... The function's name. ... by suspending execution until the returned promise is fulfilled or rejected.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is something that’s been documented in the caveats.
Check out the Babel plugin readMe
Pretty much, you are not using a normal import function which webpack provides. It’s transformed into our universalImport
While it is thennable, it’s not self evoking. “Then” in our context, is a function which executes “load”, which is a promise.
Give this a read: https://github.com/faceyspacey/babel-plugin-universal-import/blob/master/universalImport.js ——— To the discerning eye, you may be wondering if the return of import() is still thenable?? It is! However, if you don’t call .then on it, somewhere (perhaps in the components like react-universal-component that you pass it to), then it won’t perform the import. Since most of us are using modules, which we need to do something with in the then callback, that’s not a problem. But if you happen to be importing a module that does its own setup, such as attaches something to the window object, well then you just need to call .then() to trigger it. That’s a rare case these days, which is why we decided to go with the simplicity seen here. And yes, async await works too.
Thanks @zackljackson …couldn’t have explained it better. Hope that helps @hedgepigdaniel