-
Notifications
You must be signed in to change notification settings - Fork 19
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
ESM entry points in package.json resolve to an empty file #48
Comments
Thanks for the well documented issue 🙏. PR #50 will solve this. I updated it following the Stencil docs. I asked a question regarding |
Thanks for the quick reply and PR @peterpeterparker ! |
Alright, we should be good. I released the new version Can you check @thescientist13 and let me know if it is alright now? |
Thanks, was able to make some progress! But did encounter another issue. So now that the import { HTMLElement, createEvent, h, proxyCustomElement } from '@stencil/core/internal/client';
export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client'; My "quick fix" recommendation for this is to make it explicit by moving @stencil/core out of
OR You could make it implicit as a (My vote would be option 1) Let me know if you have any questions / need more info. I can open a new issue for this if you prefer. 👍 |
Thanks for double checking and for the feedback, that's not good, there should be no reference on Stencil. I following exactly what's in the doc and starter kit, I will investigate further! In what type of apps and how are you importing the component? Can you provide a sample or tell me a bit more so that I can reproduce the issue and share it too? Thanks a lot for your help! |
Sure, you can see a PR of my attempts here in my studio website repo, that I'm migrating to use WCs w/ Lit and here is how I am using it. import { css, html, LitElement, unsafeCSS, TemplateResult } from 'lit';
import { customElement } from 'lit/decorators.js';
import 'web-social-share';
@customElement('app-social-share')
export class SocialShareComponent extends LitElement {
protected render(): TemplateResult {
const share = {
displayNames: true,
config: [{
facebook: {
socialShareUrl: 'https://peterpeterparker.io'
}
}, {
twitter: {
socialShareUrl: 'https://peterpeterparker.io'
}
}]
};
return html`
<div class="container">
<div class="row">
<h2 class="header">Interact + Share</h2>
<web-social-share show="true" share=${share}></web-social-share>
</div>
</div>
`;
}
}
Using my own project Greenwood to support modern ESM / build + bundle-less workflows for things like:
Similar tools in the space are Snowpack, Vite, and the Modern Web Suite. The Lit docs give a good breakdown of those requirements / expectations for this kind of tooling, so that's what I am trying to support on my end as well. 😃 |
Thanks a lot for the details, will have a look / try tomorrow or next days. |
I fixed the issue and published a new version as a breaking changes since I modified the custom element entry. Let me know if it works out but, according my test, it should be alright. I was able to import and use the component in a lit starter kit. Note: it contains some TODO, just limited my self to the bare minimum test ;)
|
Thanks, I really appreciate it! It does looks like all the "ESM" fields in package.json got reverted back to pointing to an empty entry point file again though? (dist -> dist/esm). 😢 I think part of what is contributing to the confusion is that the usage for pulling in the WC itself is not super clear / obvious. Without hints from a package.json, it's not clear how tools / users would know to use this new path from your snippet instead import 'web-social-share/dist/components/web-social-share'; Which seems to differ from what I see in the stencil docs as recommended by this README, which implies a function call is required? <script type="module">
import { defineCustomElements } from '@ionic/core/loader/index.es2017.mjs';
defineCustomElements();
</script> But i don't see that in your latest example? Also, it looks like that file still references TL;DR I think we are close, I think what is just needed is:
Then, when these fields point to the new entry point from your example, NodeJS and tools using those fields as hints should automatically find your entry point. Then either of these variants should work 🙌 import 'web-social-share';
import { xxx } from 'web-social-share'; Thanks again, and sorry for all the trouble. 🥺 |
The entry points in the There are different way to consume the component, indeed you can use the
Or
or with the custom element
Depends of the app and goals. In any case, it never needs Stencil as a dependency. Therefore, I think we are close and nothing more need to be done. As I said in my previous comment, using the last method I was able in a sample project to import and use successfully the lib in a lit element component (see my previous code). Being said, if you can provide a sample repo that narrow the exact issue, happy to give it a try. Likewise, PR for the README.md is welcomed. |
Ah, so yeah, looks like these are known issues / open items with Stencil
If i have some time I will try and play around see if if there is a work around to make it work in its current state for ESM based workflows in NodeJS and submit some instructions for that, since as you say, each time you run your build, it will just keeping resolving back to that initial, empty, state. I will try the loader option as well, to see if explicitly referencing the file as a deep import helps. |
Cool! Keep me posted and thx for the help |
Got it working (with a couple tweaks to a fork I made). Left a comment in the Stencil issue, hopefully they will be able to resolve it. |
Ah cool 👍 If your tweaks need applies to this component, send me a PR if you do not mind, that would be super. |
Woops, realized I dropped the wrong link in my previous comment. Here was my feedback to the Stencil team in that issue - ionic-team/stencil#2826 (comment)
So, yes, I am totally happy to open a PR, but I guess it is really is up to you because as we see here, everything gets "reset" when you release and run the Stencil CLI so not sure if that's something you would want to "maintain" as it were each time? Plus would want to document the bit about dynamic import vars I suppose. Let me know though if that all sounds good to you though, happy to upstream what I have here at least if it helps! |
Thanks for all the details. Yes agree with you, maybe we should check a bit first to see if something is moving on the Stencil side before merging a new PR. Not against at all, as you said, if it needs to be maintained and needs some documentation, it is maybe worth to "wait a bit" to check if no proper solution comes from the compiler. Ultimately, if not, sure go on with the PR. Does that make sense? Agree with this plan? |
Yeah, I am OK with staying in a holding pattern for now, no rush from my end. I will probably swing back a little later on anyway to ask some questions on usage / styling in the context of my project and use case, now that I have things working, so will try and preserve your time and support for that. 🙏 Thanks for all your help so far! |
Awesome, sounds like a good plan! Thank you |
I was looking around the best alternative for Lit elements and wanted to try the lazy loading concept of Stencil. But I also see my index.js is pointing to an empty files only :(. Can we take this on priority please, I was doing POC for explaining stencil is best :p and now I can't explain lol. is there any way I can change entries in the dist folder |
Alright, so first let's reopen this 😉. @thescientist13 can you provide your modifications as PR, it seems it can be interesting to some. afterwards and in addition, should we add something in the README? finally, it the solution is to point the entry in package.json to a different entry point, I think we can submit PRs to the Stencil sample repo and doc, might be useful if it is the effective solutions for everyone. |
agree on both counts and will do. Should be able to get that up a little later on tonight for review.
So I see two possible, equally viable options from the Stencil side
I'm not really sure what the right fix is unfortunately, or rather what the intention was from the Stencil team. I'm hoping to use the issue opened in their repo as the main driver of resolution though. 🤞 I myself actually arrived at the file i did by reverse engineering your live demo and seeing that you were using that file, so I tried it locally and it worked. So mostly just trial and error, just to be forthcoming in that regard. 😅 I believe the simplest solution given the current available artifact in npm, and what I would propose PR is:
|
@thescientist13 thanks in advance 🙏
agree with both scenario 1. or 2., make sense 👍. I would say 1. is maybe the clean solution, 2. is the acceptable one, both good in any case. let's keep an eye open and see how it moves forward stencil's side (currently the maintainers are in xmas holidays) |
cool, thanks guys, its working now 🤐. stencil needs to update the documentation to point to |
Wort to notice that
In addition to what we discuss above about documenting Stencil, if the entry point should be modified in Stencil, the warning detection should be updated too. |
I have just release @thescientist13 PR in v8.0.1. Thanks! |
Guys just another help please, its not related to this, but little guidance. I am having my tsx template in another .js file say template-three.js has simple onClick which only alerts import { h } from '@stencil/core';
export const template_three = () => {
return <button onClick={() => alert()}>Template three here</button>;
}; when I try to call this method my importing in component tsx like this import { Component, Fragment, h, Host, State } from '@stencil/core';
@Component({
tag: 'component-two',
styleUrl: 'component-two.css',
shadow: true,
})
export class ComponentTwo {
@State() showComponentOne: any;
method: any;
template: string = '';
constructor() {}
componentWillRender() {
this.fetchComp(2);
}
fetchComp(type) {
let this_ = this;
switch (type) {
case 0:
import('./template').then(module => {
this.showComponentOne = module.template_one;
});
break;
case 1:
import('./template-two').then(module => {
this.showComponentOne = module.template_two;
});
break;
case 2:
import('./template-three').then(module => {
this.showComponentOne = module.template_three;
);
break;
default:
break;
}
}
clicked() {
alert();
}
methodHere() {}
render() {
let this_ = this;
return this.showComponentOne ? this.showComponentOne.apply(this) : <div></div>;
}
} View renders, but event listners are not working, not even a simple alert :(. When I inspect, I don't see any event attached to button , however if same function I keep inside component class, it works :( !!! Can you tell me what I am doing wrong in stencil syntax. I can't keep templates in component only cause I have many UI's for same logic. |
Awesome, I will swap out my fork back to this package in a few and report back. @pranav-js |
@pranav-js give a try to the Stencil Slack Channel for your question, not sure what you are trying to achieve and it isn't related to this issue, thanks in advance and good luck. |
@peterpeterparker can confirm that pointing back to upstream in my project now, everything is working. 💯 |
Awesome! Thanks again for the PR and feedback |
@thescientist13 hahha, you found my lit comment too for same thing . I was trying lit and stencil together to see which is possible I like stencil but not able to separate out only template part in other file with events attached (view works). same thing in react works though. will have to put some StackOverflow question. |
Was just testing this out and was debugging why nothing was showing up on the screen, but without any errors and it looks like the ESM / module entry point in package.json ultimately leads to an empty file?
module
field (and other fields) that point to a dist/index.jsLooking forward to giving this a try! ✌️
Somewhat related, but the formal standard to wrangling all these fields is the new export map spec. Might be a nice way to clean all those up, since only
main
is a standard as far as NodeJS is concerned.The text was updated successfully, but these errors were encountered: