Dynamic import not statically analyzable breaks tools like vite
Stencil version:
@stencil/[email protected]
I'm submitting a:
[x] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior: The following code relies on webpack specific import behaviour, other tools like vite and esbuild won't work because the import path is not statically analyzable without evaluating the expression
https://github.com/ionic-team/stencil/blob/cfd5d39bad4ce2cab431595ae8c8f11d1fabb192/src/client/client-load-module.ts#L23
Expected behavior:
Import calls should be statically analyzable, replace loadModule() with a direct import() call
Steps to reproduce:
https://github.com/haikyuu/vite-ionic
The same thing happens with esbuild, it isn't able to bundle the dynamic import and it will fail at runtime https://github.com/remorses/stencil-reproduce-2827
Related code:
Other information:
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.
Thank you for using Stencil!
Reopening. Most of theses kinds of issues should be resolved by using custom elements directly and not relying on Stencil lazy loading. Work is already underway to provide full support for this and we will be sharing more soon. Thanks!
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.
Thank you for using Stencil!
@stencil/core version: 2.5.2, @ionic/core: 5.6.6, @ionic/vue: 5.6.6, vite: 2.3.0,
index-7a8b7a1c.js:1 TypeError: Failed to fetch dynamically imported module: http://localhost:3000/@fs/C:/DevJS/_CJ_ViteVueTS/node_modules/.vite/ion-app_8.entry.js undefined
This issue exists with latest versions of vite and rollup. In other words do not build with anything except webpack.
Actually this is a problem with ionic, not vite/rollup
I mean stencil
I mean stencil
Thats exactly what I'm saying: ionic-vue do not compile/build corretly in vite (esbuild) nor rollup.
The whole point of this issue is in fact to make stencil compatible with other dev/build tools (namely vite and rollup) so that we can use vite + ionic.
@liamdebeasi are you saying that there is a workaround for this ? could you please explain it ? currently a single component made with Stencil blocks me from using a new build system. Thank you
For developers using Stencil directly, you can output your components using the Custom Elements Bundle: https://stenciljs.com/docs/custom-elements. This approach does not use lazy loading which should help with static analysis in Vite.
For developers using Ionic Framework, we do have plans to use this custom elements output, but we will be doing that (at least for Vue initially) in Framework v6.
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.
Thank you for using Stencil!
For developers using Stencil directly, you can output your components using the Custom Elements Bundle: https://stenciljs.com/docs/custom-elements. This approach does not use lazy loading which should help with static analysis in Vite.
For developers using Ionic Framework, we do have plans to use this custom elements output, but we will be doing that (at least for Vue initially) in Framework v6.
When you import defineCustomElements from a custom-element bundle, and it loads an entire library, vite makes a vender.js file for me 28 components, 800k, is that all being loaded into the browser?
@mbulfair yep. The idea with the custom-element-bundle is that you're supposed to just import / define the things you need per module (and only use defineCustomElements for prototyping). It's up to you to decide what to bundle in what module.
@johnjenkins so until stencil better supports builders like snow/vite, a way to get around this is to import directly from the custom element bundle, yes you will have to import everything you need manually.
hopefully can get my PR merged :)
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.
Thank you for using Stencil!
Is there any demo repo for stencil with esbuild?
👋 This issue has been fixed with the v2.16.0 release of Stencil. As a result, I'm going to close this issue. If you believe that the bug still exists, please feel free to open a new ticket. Thanks again!
EDIT: This functionality is gated under a new flag, experimentalimportinjection. Folks wishing to make use of the functionality should enable this flag and recompile their Stencil projects.
@rwaskiewicz do the next version of ionic will be built with the flag?
We will be incorporating these changes into an upcoming release of Ionic. Please follow https://github.com/ionic-team/ionic-framework/issues/23823 for updates.