-
Notifications
You must be signed in to change notification settings - Fork 781
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
Importing Stencil-generated custom elements in another Stencil project fails #2531
Comments
Facing the same problem, Any update? |
I am facing a similar problem. Is there clear guidance on how to use a Stencil Component Library's "custom elements" output within another Stencil Component Project? The use-case here is a set of shared-base-components being used within multiple application-web-components. This is analogous to Angular Material components being used within many Angular Applications. A consumer of one of the application would be responsible for loading the application web components and NOT be responsible for loading the shared components. |
It appears only using Clear documentation on this use-case would be a huge benefit. I assume StencilJS projects consuming other StencilJS components would be a use-case worth documenting, for both build-time linking and runtime lazyloading scenarios. |
Any updates here? This is really keeping stencil from being scalable. I had a look into the stencil runtime and it seems the initializeComponent function does not care about the source of a component. It just looks if the build is lazy. There I currently no way to do this, as far as I see it! |
BTW: Still a problem in 2.4.0 |
I made appropriate changes in stencil compiler and runtime and it now works - you may check it https://github.com/CODE-AND-MORE/stencil/tree/codeandmore (build and test or Quick summary of changes:
|
@lxg @SheepFromHeaven Can you test my fork and check it for your use case? |
Hi, sorry, I’m not using Stencil in current projects anymore … switched to pure TSX for web components. |
@MarkChrisLevy was on vacation. Will try 👍 thx! |
Hey @MarkChrisLevy. I tried, but it did not seem to work. I installed your version in both of the projects. As soon as I import one of the components in my lazy bundle, the whole library is being imported 🙁 |
@SheepFromHeaven Hmm, I'm using it without any issues. Can you show me your stencil conf for building a component? See how I'm doing it: ionx. |
As far I know Stencil team plans to improve CustomElements output target and would be great to hear more about it, any word @rwaskiewicz in this topic? Thanks. |
Hey all 👋 I don't have anything concrete to share at the moment as far as timelines are concerned on specific improvements. @MarkChrisLevy did you have any specific thoughts on how to improve the CustomElements output target? |
@rwaskiewicz Uhh, sorry for not answering, I didn't see your reply. There are several issues with current implementation of CustomElements, the main issue is that it cannot be used alongside with LazyLoad build - CustomElements components just doesn't load. Please have a look what I did to make it work and some nice improvements: #2531 (comment) |
It does work for me on the latest stencil generated by package.json
stencil.config.ts
stencil elements are just normal elements. |
is there any update??? |
+1 !!! Hope it will be fixed soon :) |
@rwaskiewicz do you have any news to share ? Thank you |
Does Ionic/Stencil have any advice on how to write unit or e2e tests in a stencil project that depends on other stencil projects' compiled components? We are considering running these tests in Playwright or Cypress, as we have a mono repo with a base library of stencil components and another library of stencil components that use the base library. Ideally, we would prefer just to use the stencil testing setup. Before stencil v4 we just did a hacky direct path to the other library's component, but now it is not working and trying to find a better solution. Ideally, it would be better to have some guidance on registering custom elements from any source in the stencil unit or e2e tests. Or, if this is not possible, some reply to this thread would be much appreciated. |
Wondering if anyone has been able to get this working in the context of unit tests? Similar to @duncanhunter's issue. Here is what my test file looks like: // my-text.spec.tsx
import { newSpecPage } from '@stencil/core/testing';
import { Text } from './my-text';
import { h } from '@stencil/core';
import { MyButton } from 'component-library-a/dist/components/my-button';
// ^^^ Previously errored: 'Cannot use import statement outside a module' but fixed by using 'babel-jest'.
it('should render my component', async () => {
const page = await newSpecPage({
components: [Text, MyButton],
template: () => (
<my-text ......></my-text> // ERROR: Unexpected token: '<'
)
});
expect(page.root).toEqualHtml(`...... ...so it's very basic. Error: template: () => <my-text></my-text>
^
SyntaxError: Unexpected token '<' I have also set Having to manually set I've added this comment here as it's a knock on from trying to figure out how to import a Stencil component library into another Stencil component library. |
We reverted from having stencil project that depends on other stencil projects and avoid the headaches. |
Stencil version:
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:
When I create a set of custom elements with Stencil using the
dist-custom-elements-bundle
target and try to use them in another Stencil project by registering the custom element withcustomElements.define
, I get the following errors in the console:When I import the component in the same way in a project that isn’t Stencil, it works fine. (#2516 aside.)
Steps to reproduce:
I have created a demo here: https://github.com/lxg/stencil-elements-poc
elements
dir contains the elements library, currently containing only theui-button
element.component
dir contains another Stencil project which demonstrates the issue.site
dir contains an 11ty example site where importing theui-button
element works.The text was updated successfully, but these errors were encountered: