-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Make packaging compatible with Node.js #19041
Conversation
Any update on this? |
This is a large change that we'll have to be careful with. So no ETA yet but it's on our radar. |
Thanks for working out this PR, I hope this issue will be resolved soon, and this approach of naming the files Maybe a bit off topic, but I'm wondering if this isn't something that can/should be addressed in Vite. Looking in the package.json of Fortawesome, I see there is a |
It's not Vite that has a problem with the names, but Node.js. If you use a bundler, you can bundle the files into a proper package. Vite does not bundle external dependencies by default and just lets Node run them directly. The problem here is that this package is not compatible with Node.js |
@robmadole @tagliala I'm happy to rebase this PR when you're ready to merge it. I'm not going to try to keep it up-to-date until you give the go ahead as that's a near impossible task. I'd really like to work with you to get this in. It's now the most upvoted PR by a factor of 2x: https://github.com/FortAwesome/Font-Awesome/pulls?q=is%3Apr+is%3Aopen+sort%3Areactions-%2B1-desc Can you share if there are certain concerns you have or what testing you'd like to do to gain confidence that this change will be transparent to users? Or is there a v7 on the horizon that this could be included in if you still have some type of concern? |
aaah, I get it now. Thanks for explaining and working out this fix! |
@benmccann thanks for doing this and your willingness to help. The issue is purely one of breaking someone's existing build or project. So we have to be confident enough that whatever changes we make won't do that or that the percentage of folks who might be broken is low enough to be acceptable. For example, if it breaks Webpack 1.0 is that OK? The other challenge for me on this is that the NPM packages pre-date Node's move to So let me push back a bit and see if I can learn here. Our
These were best practice at the time they got added. We then added this for tree-shaking (I don't think this has anything to do with the packaging issues though but I could be wrong.)
And recently we updated to the new
So now we also need to rename files that are What I can see in Node's docs is:
This makes sense. But I've also told Node what type of file it is through So how do we proceed? Aside from trying to setup dozens of different projects (next, nuxt, vue, react, angular, ember, webpack, esbuild, require.js, etc.) and testing if a |
Hi @robmadole I would like to politely remind you of the other side of the coin. This has now broken my project and I'm now a frustrated user. But would like to ensure you that many projects have done this transition and @benmccann is constantly going to different projects and doing this exact same thing. And I'm not alone: https://stackoverflow.com/questions/73081109/getting-error-when-importing-fontawesome-icons |
@robmadole Completely empathize with your frustration and the difficulty of maintaining a project as popular as this one in the ever-shifting sands of Node.js, JS, and the web. As Ben wrote, this PR (renaming these 5 files to end in Here are some examples I could find of projects that have been through the transition or contemplated similar changes:
Tierney has a highly informative series of articles, ESM in Node.js (also on dev.to) where they go into detail about the different options and how each option interacts with Node. @ljharb's comment in #16439 gets at the technical reason
It's not easy to find examples because Hope this helps add more context. |
@robmadole I share your frustration with Node.js here! That being said, I don't make the rules and just have to follow them. I've been helping across lots of different packages at this point, so have learned the rules pretty well and am happy to share
Node.js will load a JS file as CommonJS unless the package has
Node doesn't do anything with
Hopefully by merging this PR! 😆 More seriously, we shouldn't have to test various JS frameworks (next, nuxt, vue, react, angular, ember) as they're not runtimes that execute the JS and are not bundlers that parse and compile the JS (though most do use bundlers, there's less permutations if we just consider the bundlers directly). The bundlers (webpack, esbuild) and loaders (require.js, etc.) do care about packaging changes in general. Although, I can say from experience, they just take the entry point and use it without regard to what the file extension is.
Yes! I've made this change in dozens of projects. I'm afraid I can't recall many of them as it's been at least a few months since the last one. But that's also good in a way because they were all non-eventful - if it were painful I'd be more likely to remember 😄 Searching through my inbox returned mostly unrelated results, but I did manage to find that Three.js added a
Just to be clear, the tooling we're talking about here is Node.js! They're pretty much the largest JS runtime out there besides Chrome. I can reproduce this error just running long-term suggestion This whole mess is caused by the JS ecosystem historically having had so many different file loading formats / conventions. Luckily this problem is starting to be resolved with the standardization of ESM. This problem only really goes away when everyone switches to ESM. When in the transition you want to do that is a project-by-project choice. But you could probably avoid a lot of complication by going ESM-only or at least ESM-first. By ESM-first I mean add |
Fantastic @rdela and @benmccann. So super helpful. I'm confident enough that we can try this then. I'll slot this for the next upcoming release. I appreciate your time and patience and the service to the community at large. |
Thanks @robmadole! Let me know when you're ready to merge and I can resolve the merge conflicts then. |
@benmccann we have another private repository (because it contains our commercial software) where these files get built. It's a simple enough change. Nothing additional needed from you I'll just double-check what you've done here as a reference. |
@rdela I won't comment beyond this as I don't want to get in the way of y'all's work but just wanted to say I really appreciate how nice your comments here are to me. One of the kindest pings I've ever gotten on GitHub ❤️ |
The simplest approach is to do CJS-only, since any node program that understands ESM can import CJS (or bundle it). The complexity arises when attempting to ship native ESM. |
@ljharb Somebody's gonna be first to ripping off the CJS bandaid. Better to be ready for it. |
@mikestopcontinues its already happened, and the result is a ton of user pain, and virtually no adoption. Do it at your own risk :-) |
This is primarily a client-side library. Distributing it only as CJS would be pure madness ESM works far better with modern frontend development tools in my experience. It lets you skip using stuff like |
You can only skip bundling if the rest of your app’s deps are published as native ESM, which is highly unlikely to ever be the case for most apps. I’m not aware of any inherent bugs caused by CJS/ESM conversion or bundling. |
OK! We've got this fixed and tested and ready to ship with 6.2.0. Thanks all for the patience and help. |
That is awesome news Rob, thanks! 🎉 |
Thanks! |
@robmadole My project now builds with no hacky configurations ! Thank you !!! |
Yes! It's working for me as well now. Please feel free to close this PR and all the linked issues! |
Fantastic! Thanks all again. |
Fixes #16439
Fixes #18514
Fixes #18075
Fixes #18677
Maybe #18237 as well
The current packaging is not compatible with Node.js. All files will be treated as CommonJS unless
"type": "module"
has been set or the files end with.mjs
. Adding"type": "module"
was proposed in #18720. While I'd prefer that solution since I'm all in on ESM, it's a breaking change and probably better to do in a major version. This is the safe way to fix it