-
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
bug: issues deploying to Cloud Functions #6
Comments
The output directory of If you have a standard firebase config the output from Since you're using TypeScript, it will probably be
The adapter should actually output the code you need to include. This is an example, but the var names in your output will be specific to your config. // functions/index.js
const functions = require("firebase-functions");
const admin = require("firebase-admin");
let svelteServer;
exports.svelteSSR = functions.https.onRequest(
async (request, response) => {
if (!svelteServer) {
functions.logger.info("Initializing SvelteKit SSR Handler");
svelteServer = require("./my-site/handler").sveltekitServer;
functions.logger.info("SvelteKit SSR Handler initialised!");
}
return svelteServer(request, response);
}
); The I have not used |
If the // functions/index.js
const functions = require("firebase-functions");
const admin = require("firebase-admin");
let svelteServer;
exports.svelteSSR = functions.https.onRequest(
async (request, response) => {
if (!svelteServer) {
functions.logger.info("Initializing SvelteKit SSR Handler");
- svelteServer = require("./my-site/handler").sveltekitServer;
+ svelteServer = require("../lib/my-site/handler").sveltekitServer;
functions.logger.info("SvelteKit SSR Handler initialised!");
}
return svelteServer(request, response);
}
); Importantly, this tool doesn't modify anything in your setup, it just tries to put the compiled app where it needs to be in your Functions dir by reading the config of |
I cannot get it to work with Typescript, but it works in Vanilla JS. (You don't need to import firebase-admin, fwi) Update - Problem When running, I get:
in (V.30) even when I only have one site. It says the problematic line is: const ssrDirname = hostingSite != null ? hostingSite : 'sveltekit';
at adapter (C:\web projects\svelte-next-firebase\node_modules\svelte-adapter-firebase\src\index.js:132:3) I also needed both of these for the firebase functions dependencies for anyone that comes across this: "@sveltejs/app-utils": "^1.0.0-next.0",
"@sveltejs/kit": "^1.0.0-next.31", |
Vanilla JS is the way I would recommend atm. I have created a ticket to indicate that TS is not working atm #8 and will track progress there. The short of it is, given SvelteKit already compiles your app, importing it from a TS CF may have that TS compile your app again. There's probably some config we can check for and warn the user that they need to add to get TS to ignore compilation, but that is another caveat that is Cloud Function specific. I recommend Cloud Run over Cloud Functions.
Can you share your
|
I think I found why you may be having a terrible time with this. It seems there was a logging change, so most of the helpful parts of this tool are not logged when you run the adapter. (still does not explain your |
I fixed the logging issues in |
Hi, with version 0.3.1 I am still getting the error: > Using svelte-adapter-firebase
> Cannot read property 'hostingSite' of undefined
TypeError: Cannot read property 'hostingSite' of undefined
at adapter (C:\web projects\svelte-next-firebase\node_modules\svelte-adapter-firebase\src\index.js:134:3)
at adapt (C:\web projects\svelte-next-firebase\node_modules\@sveltejs\kit\src\api\adapt\index.js:24:8)
at C:\web projects\svelte-next-firebase\node_modules\@sveltejs\kit\src\cli.js:121:10 I am not using hostingSite or site as I do not have multiple sites... |
Here is my project on github. I have not deployed to neither cloud functions nor cloud run. I am simply trying to get |
Thanks for the link to your project. Your issue reproduces on my machine. I will try to resolve the issue this evening. |
@jdgamble555 version |
Thanks for looking at this. Progress, but No Go. Good to at least see a different error. I receive this error: "hosting" does not contain at least one required match
Error with "firebase.json" config.
Expected Hosting config for site:
"default" - did you mean to specify a specific site?
with config:
"rewrites.*.source": "**"
for either a Function or Cloud Run service. You can see I have hosting in my firebase.json. I could be off here, but I believe the problem is that you are validating hosting to be an array if there is only one site, instead of an object. This line may need to be something like: const firebaseSiteConfig = typeof firebaseConfig.hosting === 'object' ? firebaseConfig.hosting : .... And this line should probably allow for an array or an object. I believe you could somehow use Again, I could be way off here... |
Your hosting config is incorrect. Rewrites is a nested field under a specific Hosting config, like this: {
"hosting": {
"public": "static",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
+ "rewrites": [
+ {
+ "source": "**",
+ "function": "ssr"
+ }
+ ],
"predeploy": ["npm run build", "npm run adapt"]
},
- "rewrites": [
- {
- "source": "**",
- "function": "ssr"
- }
- ],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "functions"
}
} The error is saying that the default Hosting config (because there is only 1) does not have a
I utilise a Joi feature to resolve this svelte-adapter-firebase/src/index.js Line 138 in eb73b16
|
And that fixed it. Don't know how I did that. Thanks! Just side note: It would be cool if you created the firebase function automatically like you have here, but actually create the function when you run deploy. Angular universal does this. Thanks! |
Great!
Given the history of people structuring their Functions every which way, I tried to reduce the restrictions and automation in favor of hints. The only requirement to make the log be quiet is that it finds a snippet of I may look into an auto-generation option, but then I'd have to deal with find and replace on function renames etc. Since it is an event that isn't going to occur often I think this is a good balance for now. |
It is not clear what the actual firebase function should load in this case. Also, there is no sveltekit/ directory. I am assuming this is the build directory that svelte-kit build creates?
This is what I have in functions/src/index.ts, and I get a deployment error: Function failed on loading user code
I also found two problems with build/index.js:
I am not sure what the firebase function should load, or how it should load it...
I feel like I am getting closer, but not sure what the code is supposed to be, and I func is not a function error when deploying...
Is this how the Firebase Function should look?
The text was updated successfully, but these errors were encountered: