question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSR fails on sub-package imports when `exports` field is defined (can't SSR Firebase v9)

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
brilloutcommented, Jul 30, 2021

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 their package.json, Vite would leave the import statements as-is, instead of transpiling them to require. (That’s the whole point of setting type: "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?

1reaction
Niputicommented, Nov 18, 2021

@worxto please open issue with a reproduction

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found