Menci / vite-plugin-top-level-await

Transform code to support top-level await in normal browsers for Vite.
MIT License
266 stars 15 forks source link

Runtime error when using "adapter-node" #38

Closed inzanez closed 1 year ago

inzanez commented 1 year ago

I just managed to pack all things into an application compiled with adapter-node. However, I get the following error during runtime: The requested module '../chunks/types.c09c3db7.js' does not provide an export named '__tla'. I guess that is the topLevelAwait export. Is there anything special that needs to be done to use that with adapter-node? I used it with the static adapter which worked fine, but in this case I will have to go with node...

inzanez commented 1 year ago

Ok, I'll answer that myself. First of all, read the README even if you used the package already in another project. The following is important if used with rollup:

topLevelAwait({
        // The export name of top-level await promise for each chunk module
        promiseExportName: "__tla",
        // The function to generate import names of top-level await promise in each chunk module
        promiseImportName: i => `__tla_${i}`
    })

And then, clear the browser cache. Seems I had a cache refreshing issue (even using ctrl + shift + r which usually does the trick). All working very well.