-
Notifications
You must be signed in to change notification settings - Fork 33
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
The requested module 'firebase/app' is expected to be of type CommonJS, which does not support named exports #47
Comments
Might be related to this similar issue in another adapter sveltejs/kit#1379 |
This isn't a bug with this adapter, by the way, because it'll happen with any. I'd also suggest upgrading to Node 14.16.1 if not 16.1.0 to solve this (because I've seen that be the reason for issues with a similar error message). |
Thanks! Confirmed that updating to Node 14.16.1 solved this issue. |
Cloud Functions latest Node.js support is |
problem persists |
finally it works by doing "npm i firebase@9.0.0-beta.6" under functions directory |
@sebmade You shouldn't need to or be expected to add |
@jthegedus my config is a just new installation of a svelte-kit app by using npm init svelte@next my-app, so I use @sveltejs/kit 1.0.0-next.127. I've import firebase-admin@9.10.0 for server side calls and firebase@9.0.0-beta.6 for client side calls. I use svelte-adapter-firebase@0.9.2 and svelte@3.34.0. |
Finally it reproduce again, you're true : install firebase in functions dir don't work Don't understand what happens, I'm open to ideas :) |
This error occurs because the Firebase (client) SDK relies on IDBIndex which is only available in Web environment, not server. Server libs:
Client (web) libs:
SvelteKit is an SSR framework, so understanding which parts of SvelteKit will execute on the server is crucial. Be careful where you use The adapter works by compiling your SvelteKit SSR dependencies so you shouldn't need to modify your With that cleared up. Here is the breakdown across SvelteKit rendering scenarios: SSR libs:
Web libs:
In your SvelteKit app if you want to use Firebase in SSR you need to use SvelteKit is less clear than other libs (like Next.js) on what executes where, which makes the usage more difficult. But the
import { browser } from '$app/env';
import { onMount } from 'svelte';
onMount(async () => {
if (browser) {
// it is safe to import firebase client sdk
}
});
Recap:
|
thanks @jthegedus for this clear explanation IDBIndex error still there if I put firebase in dependencies rather than devDependencies, I had the same problem with sapper |
I've not had this issue. I have Here is a snippet from an app: // $lib/firebase/client.js
import { initializeApp, getApps } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
const app = getApps().length === 0 ? initializeApp({...}) : getApps()[0];
function firestore() {
return getFirestore(app);
}
async function performance() {
const perf = await import('firebase/performance');
return perf.getPerformance(app);
}
export { firestore, performance }; <!-- __layout.svelte -->
<script>
import { performance } from '$lib/firebase/client';
let perf;
onMount(async () => {
if (browser) {
perf = await performance();
}
});
</script> Importing
The error happens when we At least this is my current understanding. From memory |
Describe the bug
I decided to use v9 of the Firebase API.
The biggest change to v8 is that you no longer need to load all the Firebase JS but just the functions that you are going to use.
Instead of
it is called by
In development this works fine however when running the build with the Svelte adapter I get the following error:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Being able to build without having to add something like
import firebase from "firebase/app"
Additional context
I do not know where this error is triggered but it seems related to the adapter. The initial svelte build does seem to work. With the support of ESMBuild in #39 you would expect that it should work but maybe there is a hardcoded check on firebase/app that it is CommonJS somewhere?
The text was updated successfully, but these errors were encountered: