-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESM: Dynamic import of module
does not work with Vite v4.3
#19886
Comments
With Vite 5 this got even more problematic. Here is a reproduction repository: https://stackblitz.com/edit/github-rjaduf-38mdms?file=src%2Fpages%2FHome.vue Because vitejs/vite#13530 is closed as duplicate please also have a look at vitejs/vite#14169. Is there any chance we can get rid of the dynamic Pinging @kleisauke, @curiousdannii, @sbc100 and @RReverser that were involved into the |
Looking at the comment around the Would that help in this case? i.e. is its specifically the import of |
@sbc100 That was the original plan, but it would've required a massive rewrite as none of the rest of the code is designed for async importing. Using This seems like a particular issue with Vite's bundler. It's a shame they don't appear to be interested in fixing it on their end, but maybe there are legitimate reasons why they can't. @WolfgangDrescher do you need multi environment builds? If you set it to only build for browser that code won't be emitted. |
It looks like this specific problem did get resolved since Vite However, a rewrite for asynchronous importing, as suggested by @curiousdannii, would probably be the best long-term solution for Emscripten. |
We have same problem while developing Hive Blockchain TS communication library. When our package is installed in next application, next.js bundler fails on given import('module'); |
I have a project that uses Verovio (https://github.com/rism-digital/verovio) which is a music notation engraving library in C++ that uses Emscripten with
EXPORT_ES6
to allow using it via JavaScript in the browser. When I build the project with Vite.js I get an error:If you follow the link (http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility) to the docs of Vite, it says:
I think this is thrown because of the dynamic import statement
import('module')
:emscripten/src/shell.js
Lines 194 to 202 in bec42da
I guess the dynamic import is used to support ES6? In production mode with Vite everything works fine (the above error message is thrown as a warning), but when you use it development mode Vite is not able to import the Emscripten module because of the dynamic import. Is there a way Emscripten could improve this for a better support with Vite?
Also have a look at vitejs/vite#13530 and nuxt/nuxt#21578 and the reproduction repo: https://stackblitz.com/edit/github-rjaduf?file=src%2Fpages%2FHome.vue
Maybe @kleisauke or @curiousdannii have a better understanding about this than I do?
The text was updated successfully, but these errors were encountered: