-
Notifications
You must be signed in to change notification settings - Fork 116
Can't import Firebase SDK #112
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
Comments
I believe this is because that package does't like being bundled with |
It turns out that this issue is because the packages are being bundled with Webpack. Since the developer never intended this, since it's a "backend" module and wasn't intended to be bundled. A fix for this would be to package your functions as a zip file like @DavidWells has done here https://github.com/DavidWells/function-zips/ |
i dont have experience with firebase sdk but @danew makes sense. zip it up. i'd also welcome a PR for instructions on zipping. we will be releasing more native support for this kind of thing in a couple months - please stay tuned. |
added instructions to README https://github.com/netlify/netlify-lambda/blob/master/README.md#alternative-to-netlify-lambda |
Thanks @danew / @sw-yx! This workaround does, however, cut out It makes developing harder as I'll have to write my own file watcher and proxy server to integrate with my app's framework. Looking forward to the native support! |
ok, i see. i love using firebase too and am keen to provide better DX for this. let me know if you figure out a way. |
@rick-stevens as an alternative you can still use Then you just need to create a simple build script similar to the one I linked above for build time. |
Even "zip n ship" is not a solution. |
hmm. if you can make a small repro i can take it to our platform devs. i would v much like to support this usecase in production (even without netlify-lambda) |
@rick-stevens just noting a similar stackoverflow answer https://stackoverflow.com/questions/51522280/use-firebase-sdk-with-netlify-lambda-functions/51656271 it seems that instead of using the SDK you can just use their REST endpoint? |
Hi @sw-yx, I think this is the same Stack Overflow issue I noted originally. I already tried looking into their REST API, but while this is okay for some of their services, it doesn't provide one for Firebase Storage for instance (one I need in my case). I've already switched to a full Firebase stack for my project (including Hosting and Functions), so I don't have a quick example anymore. But including firebase-admin (or other libraries like grpc as @chinchang stated) into an empty netlify-lambda project function, should be sufficient to reproduce! |
my bad, i skipped right past that SO answer. i see, its firebase storage thats needed. good enough for us to work with, thank you! |
I too switched to Firebase functions. And wanted to highlight that their functions deployment experience is much better than netlify as there is no need of packaging nor uploading node_modules. It just works. Maybe we can get a similar experience in Netlify also :) |
hey @sw-yx , yea also the REST solution does not work for Cloud Firestore, only for the Realtime Database. An integrated netlify-lambda solution would be much appreciated. |
+1000000 here. This issue is massive for us. The firebase authentication using Service Accounts is still a huge problem for us, since there is not enough documentation to clarify this process without using Google SDKs. I opened a thread on firebase-admin also to grab more attention to this. |
Hey do you still have the issue? I found a reasonable solution: add this webpack configuration to your project //./config/webpack.functions.js
const nodeExternals = require('webpack-node-externals');
module.exports = {
externals: [nodeExternals()],
}; and update your scripts inside your "scripts": {
"build:lambda": "netlify-lambda build --config ./config/webpack.functions.js src/lambda",
"start:lambda": "netlify-lambda serve --config ./config/webpack.functions.js src/lambda"
}, |
Hi @mklan, I've personally moved away from this approach all together, but by looking at the thread activity I think other people will probably have a go at this. Thanks! |
thats awesome @mklan! do you think it makes sense to build it into netlify-lambda? |
@sw-yx I am not sure what side effects this config has. |
ok. cc @renatodex |
I've been banging my head against this issue today, and finally came across this solution. It works for me, and it'd be awesome if it was documented in 👍 Thanks gang! |
in my case when I tried to bundle firebase SDK with my lambda function I faced a lot of errors and missed requirements.., so decided to move the big external dependencies with new package.json file inside “lambda” folder with the help of generate-json-webpack-plugin webpack plugin. and I edited the package.json build script , so after the “yarn build: server” I change the directory by the command “cd dist/server/” and then “yarn install”, this will create a new node_modules into the lambda folder and netlify will zip it using zip-it-and-ship-it to AWS lambda function. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Only working solution for this problem. Thanks @juanojeda |
Getting this same annoying issue on multiple nextjs websites. It makes the API routes unusable. Is there a solutions for websites using nextjs API routes and the firebase SDK? Modifying the webpack config is not possible as far as I know. Could you point me in the direction of solving this same issue just with nextjs? Thanks 🚀 |
Do you mean modifying the Next.js webpack config or the Next.js one? Also you might want to use the Essential Next.js plugin https://github.com/netlify/netlify-plugin-nextjs, or if you're already using it open an issue on that repo (if they don't already have one). |
The nextjs plugin is used by default as far as I know. I have tried modifying the next.js webpack config through the |
Are you using |
Not using |
Thanks @MKrupauskas that makes sense. I suggest opening an issue in https://github.com/netlify/netlify-plugin-nextjs. This issue thread is is for a tool called Netlify Lambda that lets you add a build step to your functions. See: |
Related
https://stackoverflow.com/questions/51522280/use-firebase-sdk-with-netlify-lambda-functions
Dependencies
The issue
I'd love to use Firebase (Firestore/Storage) in my Netlify function, though it won't even let me import any related SDK using
netlify-lambda serve
. I've tried both firebase and firebase-admin which respectively result in these delayed (5 - 10 seconds) errors:Using
firebase
:Output:
Or using
firebase-admin
:Output:
The text was updated successfully, but these errors were encountered: