svelte-adapter-firebase: bug: npm run build error
Describe the Bug
I installed the adapter, added it to my svelte.config.js and initialized firebase with firebase init.
When I run npm run build I get the following error:
> Error: Required "hosting[].rewrites" field not found for matched hosting configuration. Specify your Cloud Function with rewrite rule matching "source":"**"
TypeError: Error: Required "hosting[].rewrites" field not found for matched hosting configuration. Specify your Cloud Function with rewrite rule matching "source":"**"
at parseFirebaseConfiguration (file:///[project-path]/node_modules/svelte-adapter-firebase/src/utils.js:124:9)
at adapt (file:///[project-path]/node_modules/svelte-adapter-firebase/src/index.js:26:35)
at adapt (file:///[project-path]/alohi/node_modules/@sveltejs/kit/dist/chunks/index4.js:377:8)
at file:///[project-path]/alohi/node_modules/@sveltejs/kit/dist/cli.js:878:11
Steps to Reproduce
- Install sveltekit
- Install adapter
- Create github project
- Initialize firebase
- run
npm run build
Expected Behaviour
I expect the site to build.
svelte-adapter-firebase version
0.13.0
sveltejs/kit version
1.0.0-next.178
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 24 (13 by maintainers)
If I update the
hostingobject to include rewrites, do you have an example of what that function in<functionName>should look like infunctions/index.js?I updated it to
and now I’m getting the function in the terminal
Thanks for sharing more. Once you put the
<functionName>in thefirebase.jsonfile and re-run thebuildit will output the code to the CLI for you to copy/paste into thefunctions/index.jsPerhaps I don’t fully understand how the Cloud Function connects to everything. I’ve been using SvelteKit mostly with the static adapter, so this is my first time really leaning into the SSR side. I really want to configure everything correctly and do this in the “sveltekit way” if possible.
My
firebase.jsonafterfirebase initlooks like so:I included firestore, functions, and hosting in the init and i have them all turned on in the firebase app dashboard.
It is difficult to write a guide for this that covers all cases first time for each person as some people already have Firebase apps, some are initializing them for the first time with this. I will tweak the initial setup section because
firebase initis not the only step for that step. Ultimately you need a Firebase Hosting config with a Cloud Function matching the default rewrite rule for the adapter which is"**"as the log states.This is expected behaviour. You need to setup your Firebase project config for an SSR app. The output states this:
You do not have a Cloud Function rewrite rule in your Firebase Hosting config. See the docs for examples: https://github.com/jthegedus/svelte-adapter-firebase#firebasejson-configurations