-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
v19.0.0 build error with Hugo #609
Comments
Turns out that the umd export has to be set as:
ref. https://rollupjs.org/configuration-options/#output-exports @verlok can you kindly assign this one to me? |
@erikyo assigned |
Hey @XhmikosR, If you’re happy with our support, the documentation and the effort we've been putting on this project in the latest years, I hope you might want to buy us a coffee to show your appreciation. Or sponsor us, if you're a fan. Open-source software is great for everyone, but it takes passion and time (and coffee!) to grow and evolve. Thank you for thinking about it. |
Confirmed, thanks!
I feel you, I'm on the same boat myself, but OSS just doesn't pay enough, unfortunately. Thanks again! |
Thank you for the report @XhmikosR! 🤗 And take a look at the new ESM version, can shrink a bit the bundle size and, in general, should perform better than the umd module! |
@erikyo unfortunately, I couldn't make Hugo which is using esbuild to use the ESM version even with I'll try to experiment more with ESM later. |
I was able to get it working as a esm module using the module path and replacing this line in this way:
Anyhow i'm not sure to have set correctly the esbuild here, is that correct?
if yes it seems the esm path isn't picked correctly, maybe due the "browser" field of the package.json. Thanks for the feedback again, I'll talk to @verlok and we'll see what we can do to improve (if possible). |
Yeah, that's the correct solution AFAICT, see https://github.com/twbs/blog/tree/xmr/lazyload-esm. I would expect esbuild to pick up the ESM build automatically when |
Note that on the main repo docs, other packages are correctly picked up as ESM.
Then check out search.js or stackblitz.js |
OK I think I found the cause. Unsure if this is considered a bug in Hugo/esbuild. If you change your package.json properties to be relative then it works: "main": "./dist/lazyload.min.js",
"module": "./dist/esm/lazyload.js",
"browser": "./dist/lazyload.min.js",
"typings": "./typings/lazyload.d.ts", EDIT: I was testing the wrong branch, it doesn't fix the issue. |
@XhmikosR but you aren't on the wrong path... the problem is exactly that, we have to look at why Hugo is not picking the esm module (perhaps the main file is not called index and I cannot target |
AFAICT the other two packages we use in the main repo don't use index
either (only docsearch does).
But StackBlitz correctly uses ESM.
Weird issue for sure 🤔
…On Sat, Mar 30, 2024, 09:28 Erik Golinelli ***@***.***> wrote:
@XhmikosR <https://github.com/XhmikosR> but you aren't on the wrong
path... the problem is exactly that, we have to look at why Hugo is not
picking the esm module (perhaps the main file is not called index and I
cannot target build/esm/? file extension? ...)
—
Reply to this email directly, view it on GitHub
<#609 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACVLNOY35YOH64GGMLPI7DY2ZLRHAVCNFSM6AAAAABFOMFOY2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRXHE2TEOBWG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
That is the changes that we reverted due this issue, it is however true that Node allows you to export it in various ways, but often not all of them are supported by bundlers so we will have to find the right balance without breaking compatibility with the past and who is using this module. |
Apologies, but I observed the "native lazyload" version and became curious to explore its variances with various bundling methods, both with and without the module. In my testing approach, due to the continual data requests from the YouTube iframe, I rely on the initial 'finish' time recorded in my network panel within the developer tools. All tests are conducted against the localhost version, which retrieves videos from YouTube on the following page: http://localhost:4000/videos/ Using the esm version of vanilla lazyload (and maybe some others changes) using the umd version of vanilla lazyload It seems that the esm version is a little faster (as promised) but nothing exceptional of course.. 😇 |
I tried and it seems related to the "browser" field of the vanilla-lazyload package. Correctly the Hugo bundler is picking the version for the "browser" as suggested in the package.json, so in order to use the vanilla lazy load "natively" as ESM module even for the browser @verlok should update the "browser" field using the esm path. Not sure about the side-effects so this is only a recap of my findings. If the repo is left as it is nothing bad happens, the module can be forced specifying using the path of the esm version (e.g. Mystery solved, if you can confirm @XhmikosR, just need to go temporarily to update (or remove) the path in the vanilla-lazyload package.json browser field and you will see (without any further change) that the esm module is loaded as we wanted. @verlok please keep the module in that way for some time until the ESM support also on the node side is 100% ready. |
I just checked the documentation for the package.json and found out that the
The documentation for the
The problem is this module is only meant to be used in the browser, so I'm wondering why do I need to have both the Thoughts? |
I also asked Google Gemini, with this prompt
And the following was its reply:In your case, you'll want to define both
By defining both fields, you cater to different usage scenarios:
Here's an example structure for your
This way, your library offers flexibility for both Node.js and browser environments with bundlers. |
yep because that fields were "node related" check here: https://nodejs.org/api/packages.html#conditional-exports the browser field is a "community condition definition" https://nodejs.org/api/packages.html#community-conditions-definitions and were used to override the "conditional exports" |
To be honest I can't understand much from the nodejs.org documentation :D :D |
About the "browser" field it's a way to recommend to the bundler which version to use, and of those you actually shipping all 3 would be valid for the browser (iife and esm are the best candidates) Gemini is telling to serve the esm version as default but my suggestion is to avoid that at the moment to avoid sideeffects like the one that happened to @XhmikosR the times are changing but we are not 100% yet :) |
At present, you have the option to include a note in the readme specifying that if a user intends to utilize the ECMAScript Module (ESM) version for a bundler, they should reference this specific path instead of the conventional one: |
Did that here some days ago |
Yes I think then that it is not necessary to specify anything else... if someone really needs to, I think they will find this issue, which also explains the reason for the current situation and exactly how to solve it. |
Agreed, better keep things as is for now. Maybe mention the ESM explicit import in README.md but other than that I guess what we have now is a good compromise. |
Describe the bug
v19.0.0 build error with Hugo
To Reproduce
Steps to reproduce the behavior:
git clone https://github.com/twbs/blog.git -b xmr/deps
npm i && npm start
Expected behavior
Should not produce errors.
LazyLoad version
Please report which version of LazyLoad you're using.
Going back to v18.0.0 works; you can confirm this with
git checkout main && npm i && npm start
The text was updated successfully, but these errors were encountered: