Closed
Description
Describe the bug
When deploying SvelteKit app with basic Firebase initialisation to Cloudflare Pages I'm getting the following errors:
IDBIndex is not defined
ReferenceError: IDBIndex is not defined
After refreshing the browser window errors change to (NOTE: not a real web address):
Failed to fetch dynamically imported module: https://example.com/_app/undefined
TypeError: Failed to fetch dynamically imported module: https://example.com/_app/undefined
At the same time, in console I can see another error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "null". Strict MIME type checking is enforced for module scripts per HTML spec.
It is my understanding that the errors are caused by improper initialisation of Firebase. As I already wrap the initialisation in if (browser)
and check Firebase's isSupported
I'm not sure if the mistake is mine or is it a bug with sveltekit
/ cloudflare-adapter
.
As locally everything is working just fine, I'm leaning towards an issue with cloudflare-adapter
.
Reproduction
- Create a Git[hub/lab] project to host the example.
- Initialise skeleton project with
npm init svelte@next
- Install
@sveltejs/adapter-cloudflare
as a dev dependency. - Change
@sveltejs/adapter-auto
to@sveltejs/adapter-cloudflare
insvelte.config.js
. - Install
firebase
as a regular dependency. - Get your Firebase config from the Firebase Console.
- Add to
<script>
tag ofindex.svelte
:
<script >
import { getApp, initializeApp } from 'firebase/app';
import { getAnalytics, isSupported } from 'firebase/analytics';
import { browser } from '$app/env';
const firebaseConfig = { /* YOUR FIREBASE CONFIG */ };
let app;
if (browser) {
try {
app = getApp();
} catch (error) {
app = initializeApp(firebaseConfig);
if (isSupported) getAnalytics(app);
}
}
</script>
- Commit and push, observe the errors when Cloudflare deploys the app.
System Info
System:
OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1195G7 @ 2.90GHz
Memory: 21.88 GB / 31.07 GB
Container: Yes
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.5.0 - /usr/bin/node
npm: 8.4.1 - /usr/bin/npm
Browsers:
Chrome: 98.0.4758.80
Firefox: 97.0
npmPackages:
@sveltejs/adapter-cloudflare: next => 1.0.0-next.9
@sveltejs/kit: next => 1.0.0-next.269
svelte: ^3.44.0 => 3.46.4
Severity
blocking all usage of SvelteKit
Additional Information
No response