Skip to content
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

Problem when deploying on vercel: firebase-admin "Dynamic require of "fs" is not supported" #26

Closed
mschewe opened this issue May 19, 2022 · 3 comments

Comments

@mschewe
Copy link

mschewe commented May 19, 2022

Thanks for your great work!

I have tried to implement the magic link in a project of mine, after watching your video. But during the deployment, I ran into an error. I wonder if you did something else or have an idea of what is going wrong.

[GET] /
2022-05-19T11:35:22.005Z	95ed9510-7bb9-4266-aa8e-ba99f4568f25	ERROR	Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Dynamic require of \"fs\" is not supported","reason":{"errorType":"Error","errorMessage":"Dynamic require of \"fs\" is not supported","stack":["Error: Dynamic require of \"fs\" is not supported","    at file:///var/task/index.js:29:9","    at node_modules/firebase-admin/lib/app/credential-internal.js (file:///var/task/index.js:27224:14)","    at __require2 (file:///var/task/index.js:47:51)","    at node_modules/firebase-admin/lib/utils/index.js (file:///var/task/index.js:27772:33)","    at __require2 (file:///var/task/index.js:47:51)","    at node_modules/firebase-admin/lib/app/index.js (file:///var/task/index.js:28242:19)","    at __require2 (file:///var/task/index.js:47:51)","    at node_modules/firebase-admin/lib/esm/app/index.js (file:///var/task/index.js:28274:26)","    at __init (file:///var/task/index.js:44:56)","    at .svelte-kit/output/server/chunks/admin-979969af.js (file:///var/task/index.js:41707:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Dynamic require of \"fs\" is not supported","    at process.<anonymous> (file:///var/runtime/index.mjs:775:15)","    at process.emit (node:events:532:35)","    at emit (node:internal/process/promises:133:20)","    at processPromiseRejections (node:internal/process/promises:260:27)","    at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
Unknown application error occurred

I am using exactly the same version of firebase-admin, I have tried to copy the complete firebase/admin.ts it's exactly the same.

@jmagrippis
Copy link
Owner

Hello, thanks for your support and trying it out yourself!

My three shots in the dark regarding this are...

1. Node version?

Are you using & deploying to Node 16? Vercel recently added this! It will auto-deploy to Node 16 if you put an "engines" key in your package.json:

https://github.com/jmagrippis/with-svelte/blob/main/package.json#L52

I'd consider using a tool like Volta to pin down the version for local development tool, in case you ain't using one already! And then the usual, rm -rf node_modules, rm package-lock.json and npm i again (or equivalent to your package manager tool). And try to upload!

2. Env Vars?

Any chance you didn't add the Firebase Admin environment variables in the Vercel dashboard? I know I did that wrong many times (which is why I added that error-throwing sanity check 😅)

3. adapter-vercel version?

As it sometimes happens with SvelteKit, there are some deployment problems with the most recent vercel-adapter version...
sveltejs/kit#2400 Maybe we're being unlucky and landing on one of those? Which version of vercel-adapter specifically do you have?


So, yeah, those are my shots in the dark 😅 I assume the app works just fine locally? How about if you build and serve the build output locally? (npm run build, then npm run preview)?

Let me know how this goes!

@mschewe
Copy link
Author

mschewe commented May 25, 2022

I want to thank you for your very detailed answer!

Yesterday evening I had time to debug everything again and actually found the error.
It looks like I really was one of the unlucky people with a defective adapter-vercel.
I have now set it to the version from your repository and voila - everything works like magic!

Volta was also a good tip! I use that now in all my projects. I had used nvm before but always found the handling too cumbersome.

Thanks again for your great videos. I think it was the first time I really understood the possibilities of svelte-kit. It definitely inspired me and I will dive deeper into svelte-kit. Keep up the great videos!

@mschewe mschewe closed this as completed May 25, 2022
@jmagrippis
Copy link
Owner

Great to hear 🥳 adapter-vercel problems have happened to me quite a few times, thankfully I've gotten "lucky" versions in the livestreams so far 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants