SSR fails on sub-package imports when `exports` field is defined (can't SSR Firebase v9)
See original GitHub issueDescribe the bug
tryNodeResolve
fails on Firebase.
It swallows this exception from _resolveExports
inside resolveExports
:
Missing “.” export in “firebase” package
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 like firebase/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
Vite 2.4.4
Used Package Manager
npm
Logs
Vite doesn’t output any logs. I sent a PR to fix that: https://github.com/vitejs/vite/pull/4426
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
Firebase web 9.0.1 error Package path . is not exported
Try this: import * as firebase from "firebase/app". Found here: https://stackoverflow.com/a/68984595/903000.
Read more >vite exports is not defined | The AI Search Engine You Control
Describe the bug It seems reasonable that Firebase doesn't export this because they don't allow you to import firebase . You have to...
Read more >Using module bundlers with Firebase - Google
Module bundlers read import paths in your code and combine (bundle) your application-specific code with your imported library code.
Read more >failed to load module for ssr: firebase.config : r/sveltejs - Reddit
In the previous version, I set up in my svelte.config.js : import adapter from '@sveltejs/adapter-auto' /** @type {import('@sveltejs/kit').
Read more >CHANGELOG.md · 脚本测试11/material-ui - Gitee.com
[utils] Fix types of chainPropTypes (#23123) @oliviertassinari; [core] Fix bundles for packages without subpackages (#23157) @eps1lon ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Part of my proposal is to always externalize SSR dependencies (unless it’s added in
ssr.noExternalize
).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
type: "module"
in theirpackage.json
, Vite would leave theimport
statements as-is, instead of transpiling them torequire
. (That’s the whole point of settingtype: "module"
after all: using ESM instead of CJS.)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
type: "module"
may break things, but that would be a Firebase problem not supporting ESM users, and certainly not a Vite problem since Vite stays out of the picture here.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?
@worxto please open issue with a reproduction