Closed janniks closed 2 years ago
@rwaskiewicz do you think there's an easy way to fix this? Otherwise it might make more sense to use dist-custom-elements
and manually chunk in the vite config itself. 🤔
@janniks
I took a look at the reproduction case and can confirm that the dynamic import is failing. Looking at create-stacks/templates/template-vue/node_modules/.vite/deps/@stacks_connect.js
, it looks like Vite is currently caching a version of @stacks/connect
that is not dynamically importing components. I'm able to discern this based on the following line in the file:
/*!__STENCIL_STATIC_IMPORT_SWITCH__*/
which should be replaced with the import statements for your components. I believe this is part of the root cause - although I'm not sure how @stacks/connect
is generated/built, which makes it a little tricky to proceed here. Off the top of my head, I can see a few possibilities:
@stacks/connect
in stencil.config.ts
Can you do me a favor and validate that experimentalimportinjection is set on @stacks/connect
? Can you provide a reproduction case/branch that points me to how it's configured after that? I have a sneaky suspicion that it's the third option there, but wanna rule out the first two options first.
Thanks for the detailed response! 🙏
__STENCIL_STATIC_IMPORT_SWITCH__
/ experimentalImportInjection
not working. → released under @stacks/connect@5.0.6-alpha.a346466.0
via this pr; now I can't find the placeholder string anymore and assume it should workcreate-stacks
as new reproduction: https://github.com/hirosystems/create-stacks/tree/reproduce-stencil-experimental-importsvelte
and vue
both use vite and still show the previous error: TypeError: Failed to fetch dynamically imported module:
experimentalImportInjection
version of @stacks/connect
— https://github.com/hirosystems/create-stacks/commit/89f6e8b92808726a20dae80e9f1baa4cd822f4ebnpm install
, npm start
, click connect wallet, console errors⚡️ Codesandbox of the reproduction: https://codesandbox.io/s/github/hirosystems/create-stacks/tree/reproduce-stencil-experimental-import/templates/template-vue
The @stacks/connect
dependency itself loads the stencil component like this from the actual stencil component dependency @stacks/connect-ui
. Does that make a difference / Could that be a problem? 😬
The @stacks/connect dependency itself loads the stencil component like this from the actual stencil component dependency @stacks/connect-ui. Does that make a difference / Could that be a problem? 😬
Potentially, it depends what that defineCustomElements
function you link to is defined/what it's doing. It's not immediately clear to me if that's a Stencil generated loader package or something else 🤔
Thanks, I'm not sure -- But yes, that's all stencil generated. Same method as used here in stencil docs, and here.
Is there a better method of loading for use in another library?
I updated to stencil core 2.17 (here) but it still doesn't work. The way we import is the same as most stencil examples / ionic use-cases.
The loader
is set up in the same way ionic core is.
esmLoaderPath: '../loader'
in dist target (I have also tried leaving loader in the dist folder, same result)defineCustomElements
from loaderEDIT: Works 🚀
Prerequisites
Stencil Version
2.16.1
Current Behavior
Dynamic import failure on vite/rollup still persists.
Expected Behavior
Rebuilding with latest
experimentalImportInjection
should solve dynamic import failure on vite/rollup.Steps to Reproduce
OR
git clone git@github.com:hirosystems/create-stacks.git
cd templates/template-vue
npm install @stacks/connect@5.0.6-alpha.6be82fd.0 @stacks/connect-ui@5.0.6-alpha.6be82fd.0
npm start
Connect Wallet
buttonBackground
We have a fairly stock vue+vite sample projects in: https://github.com/hirosystems/create-stacks/tree/main/templates/template-vue → used for codesandbox
The stencil component was updated to
experimentalImportInjection
under 2.16.1. The component was rebuilt and released via npm as@stacks/connect-ui@5.0.6-alpha.6be82fd.0
.CC @rwaskiewicz https://github.com/ionic-team/stencil/issues/2827#issuecomment-1142399806
Code Reproduction URL
https://codesandbox.io/s/priceless-mcclintock-2x9n30
Additional Information
Is it possible to fix this issue with the @rollup/plugin-dynamic-import-vars plugin? If so how?
I've tried similar things to the following:
Where
connect-ui
is a stencil component via plaindist
, but used via another dependency (connect
).