stencil icon indicating copy to clipboard operation
stencil copied to clipboard

Dynamic import not statically analyzable breaks tools like vite

Open remorses opened this issue 5 years ago • 27 comments

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:

remorses avatar Feb 15 '21 14:02 remorses

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!

ionitron-bot[bot] avatar Mar 17 '21 15:03 ionitron-bot[bot]

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!

liamdebeasi avatar Mar 22 '21 19:03 liamdebeasi

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!

ionitron-bot[bot] avatar Apr 21 '21 19:04 ionitron-bot[bot]

@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.

genesem avatar May 13 '21 12:05 genesem

Actually this is a problem with ionic, not vite/rollup

stewones avatar May 13 '21 19:05 stewones

I mean stencil

stewones avatar May 13 '21 19:05 stewones

I mean stencil

Thats exactly what I'm saying: ionic-vue do not compile/build corretly in vite (esbuild) nor rollup.

genesem avatar May 13 '21 21:05 genesem

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.

AVapps avatar May 17 '21 09:05 AVapps

@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

simlevesque avatar May 19 '21 17:05 simlevesque

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.

liamdebeasi avatar May 19 '21 17:05 liamdebeasi

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!

ionitron-bot[bot] avatar Jun 18 '21 18:06 ionitron-bot[bot]

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 avatar Jun 29 '21 15:06 mbulfair

@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 avatar Jun 29 '21 15:06 johnjenkins

@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.

mbulfair avatar Jun 29 '21 17:06 mbulfair

hopefully can get my PR merged :)

johnjenkins avatar Jul 16 '21 09:07 johnjenkins

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!

ionitron-bot[bot] avatar Aug 15 '21 09:08 ionitron-bot[bot]

Is there any demo repo for stencil with esbuild?

cgpro avatar Feb 02 '22 00:02 cgpro

👋 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 avatar May 31 '22 17:05 rwaskiewicz

@rwaskiewicz do the next version of ionic will be built with the flag?

riderx avatar May 31 '22 19:05 riderx

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.

liamdebeasi avatar May 31 '22 19:05 liamdebeasi