Skip to content
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

Dynamic import not statically analyzable breaks tools like vite #2827

Closed
remorses opened this issue Feb 15, 2021 · 27 comments
Closed

Dynamic import not statically analyzable breaks tools like vite #2827

remorses opened this issue Feb 15, 2021 · 27 comments
Labels
Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team

Comments

@remorses
Copy link

remorses commented Feb 15, 2021

Stencil version:

 @stencil/core@2.4.0

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

`./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''}`

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:

@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label Mar 17, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Mar 17, 2021

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 ionitron-bot bot closed this as completed Mar 17, 2021
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 17, 2021
@liamdebeasi liamdebeasi reopened this Mar 22, 2021
@ionic-team ionic-team unlocked this conversation Mar 22, 2021
@liamdebeasi liamdebeasi removed the ionitron: stale issue This issue has not seen any activity for a long period of time label Mar 22, 2021
@liamdebeasi
Copy link
Contributor

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!

@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label Apr 21, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Apr 21, 2021

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 ionitron-bot bot closed this as completed Apr 21, 2021
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 21, 2021
@ionic-team ionic-team unlocked this conversation Apr 21, 2021
@liamdebeasi liamdebeasi reopened this Apr 21, 2021
@liamdebeasi liamdebeasi added bug and removed ionitron: stale issue This issue has not seen any activity for a long period of time labels Apr 21, 2021
@genesem
Copy link

genesem commented May 13, 2021

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

@stewones
Copy link

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

@stewones
Copy link

I mean stencil

@genesem
Copy link

genesem commented May 13, 2021

I mean stencil

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

@AVapps
Copy link

AVapps commented May 17, 2021

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.

@simlevesque
Copy link

@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

@liamdebeasi
Copy link
Contributor

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.

@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label Jun 18, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Jun 18, 2021

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 ionitron-bot bot closed this as completed Jun 18, 2021
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jun 18, 2021
@liamdebeasi liamdebeasi reopened this Jun 18, 2021
@rwaskiewicz rwaskiewicz removed the ionitron: stale issue This issue has not seen any activity for a long period of time label Aug 16, 2021
@rwaskiewicz rwaskiewicz reopened this Aug 16, 2021
@ionic-team ionic-team unlocked this conversation Nov 1, 2021
@cgpro
Copy link

cgpro commented Feb 2, 2022

Is there any demo repo for stencil with esbuild?

@rwaskiewicz
Copy link
Member

rwaskiewicz commented May 31, 2022

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

@riderx
Copy link

riderx commented May 31, 2022

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

@liamdebeasi
Copy link
Contributor

We will be incorporating these changes into an upcoming release of Ionic. Please follow ionic-team/ionic-framework#23823 for updates.

@eriklharper
Copy link

Is there any demo repo for stencil with esbuild?

Only one I can find is the repro example created by the author of this issue: https://github.com/remorses/stencil-reproduce-2827

I cloned that and updated Stencil to 2.16 and esbuild to 0.14.43 and it no longer issues the warning, so it appears to be working with the update :)

@splanard
Copy link

I still have the same problem using a design system library based on Stencil 2.16.1... 😥

@rwaskiewicz
Copy link
Member

@splanard can you please create a new issue with a minimal reproduction case please?

@SonyStone
Copy link

ate a new issue with a minimal reproduction case please?

I also have problem with Vite and Stencil 2.17.1

One of the teams trying to move Angular 17 to Vite so they informed me about the issue.

I checked with simple Angular 17 and it's working
https://stackblitz.com/edit/stackblitz-starters-imfdve?file=src%2Fmain.ts

But with Vite + Solidjs it does not
https://stackblitz.com/edit/solidjs-templates-jyeik4?file=src%2FApp.tsx

image

And I realy don't now what to do with it. Angular 17 don't have access to customize Vite config to do copy or something

@rwaskiewicz
Copy link
Member

@SonyStone

At this time, Stencil v2 is no longer supported. I suggest upgrading to Stencil v4 if possible, which has the latest + greatest updates/support for Vite.

Otherwise, you may be able to see if experimentalImportInjection(docs link) in your stencil.config.ts file helps here.

If the issue still persists with Stencil v4 and experimentalImportInjection (note, we renamed this field to enableImportInjection in later versions of Stencil), can you please do me a favor and open a new issue?

@SonyStone
Copy link

@rwaskiewicz
No, still not working. I updated Stencil to version 4 and it didn't help

image
https://stackblitz.com/edit/solidjs-templates-jyeik4?file=package.json

I tried with and without enableImportInjection option

@shailen-sovtech
Copy link

Hi all, I am building a POC using the latest release of React components for What3Words but it still breaks vite. I am getting this error.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team
Projects
None yet
Development

Successfully merging a pull request may close this issue.