-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
SSR fails on sub-package imports when exports
field is defined (can't SSR Firebase v9)
#4425
Comments
What do you think of following proposal?
This would solve the Firebase problem as Vite wouldn't even touch the Firebase library in dev. |
What if a package is only distributed as ESM? I think we'd still need to detect CJS vs ESM because sometimes we'll need to do an I think the particular case in this issue is tricky because Vite tries to handle this import as a single package, but with the |
When the user-side code's Bottom line: even with ESM support, there is no need to resolve SSR dependencies. From an SSR perspective, what lives in
I see. Just to be sure we are on the same page: do you as well see my proposal as a solution to the Firebase problem? |
I'm going to preface this by saying that there are so many combinations of this stuff that I always get a bit confused I still wonder with your proposal how would you treat a third-party ESM module? As an example, see here: vitejs/vite-plugin-react#30. Vite today can't externalize
I don't know if I totally understand the details of the proposal well enough yet, but right now I'm not seeing how it'd fix the issue. Your proposal still seems helpful regardless (I just chimed in with an explanation for that on #4340 (comment)). But for this issue, the problem is resolving the module and it's not clear to me how you skip that since you need to figure out whether to do an |
See my comment about ESM #4340 (comment). Let me know whether you now see #4340 as the solution to the Firebase problem. |
Unfortunately, it won't fix Firebase because loading is much more broken than resolving. If you fix the resolving then you'll get |
Why isn't Firebase externalized? |
Shouldn't Firebase be externalized anyways? |
It should be externalized, but isn't because of the bug discussed in this issue. See the issue description for an explanation. However, unfortunately externalizing it doesn't help because loading is broken. Vite tries to do |
Part of my proposal is to always externalize SSR dependencies (unless it's added in Because Firebase is externalized, the loading will be done by Node.js, not by Vite. With my ESM Plan proposal, because all SvelteKit users have It will then be Node.js that 1. resolves the firebase import and 2. loads the firebase code. Things will then work. Why am I so confident? Because Firebase is already used by bunch of vanilla Node.js users today. Although The whole point of my proposal is to get Vite out of the way and let Node.js handle things. Does that make more sense? |
Just to be clear, are you saying that changing it to do the loading would also be part of the plan? If so, I'd highly support that. If you're saying that's already supposed to be done then I think there might be another issue to solve because as far as I can tell, Node never loads libraries today even if I add them to
|
Yes and I'm glad we agree 👌:-).
Are you sure it's not already the case? Isn't that precisely the whole point of externalizing a dep? To me "externalize" = let Node.js handle it. Either way, externalized deps should definitely not be loaded by Vite (IMO). I will sum up my proposal into an actionable step-by-step plan. |
Actually, I'm not so sure now. It looks like it often does work. I will have to see if I can come up with a good reproduction. Unfortunately most of the cases I'm seeing also are hitting another bug and it's difficult to untangle |
This is likely fixed by #5210. Could someone verify? |
There were just some new instructions for testing changes added to the contributing guide (79c2a49). I tried to follow these steps, but was unable to @aleclarson when I try to build your PR (#5210), I get some build failures:
Perhaps if you rebase against |
Hmm, I'm not sure why I had difficulty building the PR before, but I just tried again and was able to build it. I can confirm it does indeed fix this issue! |
This is fixed in 2.7.0-beta.3: #5544 |
Still catch this @2.7.0-beta.3 |
@worxto please open issue with a reproduction |
Describe the bug
tryNodeResolve
fails on Firebase.It swallows this exception from
_resolveExports
insideresolveExports
:It seems reasonable that Firebase doesn't export this because they don't allow you to import
firebase
. You have to import a sub-package likefirebase/functions
, etc. I don't see anything in the Node docs that says you must export.
As a result, Firebase is not treated as external eventhough it provides a CJS build. This in turn causes SSR to fail when using Firebase
Reproduction
https://github.com/benmccann/sveltekit-firebase
System Info
Used Package Manager
npm
Logs
Vite doesn't output any logs. I sent a PR to fix that: #4426
Validations
The text was updated successfully, but these errors were encountered: