netlify-lambda: Can't import Firebase SDK
Related
https://stackoverflow.com/questions/51522280/use-firebase-sdk-with-netlify-lambda-functions
Dependencies
{
"firebase": "^5.8.2",
"firebase-admin": "^7.0.0",
"netlify-lambda": "^1.3.1",
}
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:
import firebase from 'firebase/app'
import 'firebase/firestore'
exports.handler = (event, context, callback) => callback(null, {
statusCode: 200,
body: 'OK'
})
Output:
netlify-lambda: Starting server
Lambda server is listening on 9000
Hash: e3817619e6c76f23fc78
Version: webpack 4.29.0
Time: 3210ms
Built at: 02/02/2019 11:55:21 PM
Asset Size Chunks Chunk Names
firebase.js 2.72 MiB 0 [emitted] firebase
Entrypoint firebase = firebase.js
[10] external "fs" 42 bytes {0} [built]
[12] ../node_modules/firebase-admin/lib/utils/error.js 34.8 KiB {0} [built]
[14] ../node_modules/firebase-admin/lib/utils/validator.js 7.25 KiB {0} [built]
[56] ../node_modules/firebase-admin/lib/utils/deep-copy.js 2.6 KiB {0} [built]
[115] ../node_modules/firebase-admin/lib/auth/credential.js 15 KiB {0} [built]
[235] ../node_modules/firebase-admin/lib/index.js 1.36 KiB {0} [built]
[261] ../node_modules/firebase-admin/lib/auth/auth.js 20.5 KiB {0} [built]
[262] ../node_modules/@firebase/database/dist/index.esm.js 592 KiB {0} [built]
[264] ../node_modules/firebase-admin/lib/messaging/messaging.js 48.8 KiB {0} [built]
[265] ../node_modules/firebase-admin/lib/storage/storage.js 4.98 KiB {0} [built]
[354] ../node_modules/@google-cloud/firestore/build/src/index.js 52.9 KiB {0} [built]
[422] ./components/serviceAccountKey.json 2.32 KiB {0} [built]
[423] ./firebase.js 1.17 KiB {0} [built]
[424] ../node_modules/firebase-admin/lib/default-namespace.js 1.16 KiB {0} [built]
[425] ../node_modules/firebase-admin/lib/firebase-namespace.js 18.4 KiB {0} [built]
+ 780 hidden modules
WARNING in ../node_modules/grpc/src/grpc_extension.js 32:12-33
Critical dependency: the request of a dependency is an expression
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48
Critical dependency: the request of a dependency is an expression
@ ../node_modules/grpc/src/grpc_extension.js
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67
Critical dependency: the request of a dependency is an expression
@ ../node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
@ ../node_modules/grpc/src/grpc_extension.js
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/hash-stream-validation/index.js
Module not found: Error: Can't resolve 'fast-crc32c' in '/repos/test/node_modules/hash-stream-validation'
@ ../node_modules/hash-stream-validation/index.js
@ ../node_modules/@google-cloud/storage/build/src/file.js
@ ../node_modules/@google-cloud/storage/build/src/index.js
@ ../node_modules/firebase-admin/lib/storage/storage.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/bytebuffer/dist/bytebuffer-node.js
Module not found: Error: Can't resolve 'memcpy' in '/repos/test/node_modules/bytebuffer/dist'
@ ../node_modules/bytebuffer/dist/bytebuffer-node.js
@ ../node_modules/protobufjs/dist/protobuf.js
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/write-file-atomic/index.js
Module not found: Error: Can't resolve 'worker_threads' in '/repos/test/node_modules/write-file-atomic'
@ ../node_modules/write-file-atomic/index.js
@ ../node_modules/gcs-resumable-upload/node_modules/configstore/index.js
@ ../node_modules/gcs-resumable-upload/build/src/index.js
@ ../node_modules/@google-cloud/storage/build/src/file.js
@ ../node_modules/@google-cloud/storage/build/src/index.js
@ ../node_modules/firebase-admin/lib/storage/storage.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
Or using firebase-admin:
import * as admin from 'firebase-admin'
exports.handler = (event, context, callback) => callback(null, {
statusCode: 200,
body: 'OK'
})
Output:
netlify-lambda: Starting server
Lambda server is listening on 9000
Hash: e3817619e6c76f23fc78
Version: webpack 4.29.0
Time: 3102ms
Built at: 02/02/2019 11:53:21 PM
Asset Size Chunks Chunk Names
firebase.js 2.72 MiB 0 [emitted] firebase
Entrypoint firebase = firebase.js
[10] external "fs" 42 bytes {0} [built]
[12] ../node_modules/firebase-admin/lib/utils/error.js 34.8 KiB {0} [built]
[14] ../node_modules/firebase-admin/lib/utils/validator.js 7.25 KiB {0} [built]
[56] ../node_modules/firebase-admin/lib/utils/deep-copy.js 2.6 KiB {0} [built]
[115] ../node_modules/firebase-admin/lib/auth/credential.js 15 KiB {0} [built]
[235] ../node_modules/firebase-admin/lib/index.js 1.36 KiB {0} [built]
[261] ../node_modules/firebase-admin/lib/auth/auth.js 20.5 KiB {0} [built]
[262] ../node_modules/@firebase/database/dist/index.esm.js 592 KiB {0} [built]
[264] ../node_modules/firebase-admin/lib/messaging/messaging.js 48.8 KiB {0} [built]
[265] ../node_modules/firebase-admin/lib/storage/storage.js 4.98 KiB {0} [built]
[354] ../node_modules/@google-cloud/firestore/build/src/index.js 52.9 KiB {0} [built]
[422] ./components/serviceAccountKey.json 2.32 KiB {0} [built]
[423] ./firebase.js 1.17 KiB {0} [built]
[424] ../node_modules/firebase-admin/lib/default-namespace.js 1.16 KiB {0} [built]
[425] ../node_modules/firebase-admin/lib/firebase-namespace.js 18.4 KiB {0} [built]
+ 780 hidden modules
WARNING in ../node_modules/grpc/src/grpc_extension.js 32:12-33
Critical dependency: the request of a dependency is an expression
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48
Critical dependency: the request of a dependency is an expression
@ ../node_modules/grpc/src/grpc_extension.js
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67
Critical dependency: the request of a dependency is an expression
@ ../node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
@ ../node_modules/grpc/src/grpc_extension.js
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/hash-stream-validation/index.js
Module not found: Error: Can't resolve 'fast-crc32c' in '/repos/test/node_modules/hash-stream-validation'
@ ../node_modules/hash-stream-validation/index.js
@ ../node_modules/@google-cloud/storage/build/src/file.js
@ ../node_modules/@google-cloud/storage/build/src/index.js
@ ../node_modules/firebase-admin/lib/storage/storage.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/bytebuffer/dist/bytebuffer-node.js
Module not found: Error: Can't resolve 'memcpy' in '/repos/test/node_modules/bytebuffer/dist'
@ ../node_modules/bytebuffer/dist/bytebuffer-node.js
@ ../node_modules/protobufjs/dist/protobuf.js
@ ../node_modules/grpc/index.js
@ ../node_modules/google-gax/build/src/grpc.js
@ ../node_modules/google-gax/build/src/index.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
@ ../node_modules/@google-cloud/firestore/build/src/v1beta1/index.js
@ ../node_modules/@google-cloud/firestore/build/src/index.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
WARNING in ../node_modules/write-file-atomic/index.js
Module not found: Error: Can't resolve 'worker_threads' in '/repos/test/node_modules/write-file-atomic'
@ ../node_modules/write-file-atomic/index.js
@ ../node_modules/gcs-resumable-upload/node_modules/configstore/index.js
@ ../node_modules/gcs-resumable-upload/build/src/index.js
@ ../node_modules/@google-cloud/storage/build/src/file.js
@ ../node_modules/@google-cloud/storage/build/src/index.js
@ ../node_modules/firebase-admin/lib/storage/storage.js
@ ../node_modules/firebase-admin/lib/firebase-namespace.js
@ ../node_modules/firebase-admin/lib/default-namespace.js
@ ../node_modules/firebase-admin/lib/index.js
@ ./firebase.js
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 31 (12 by maintainers)
Commits related to this issue
- Integrate Firebase firestore with netlify lamda functions - https://github.com/netlify/netlify-lambda/issues/112#issuecomment-488644361 — committed to sabinbajracharya/sabinbajracharya.github.io by sabinbajracharya 5 years ago
Hey do you still have the issue? I found a reasonable solution:
add this webpack configuration to your project
and update your scripts inside your
package.jsonto take a custom webpack config: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
netlify-lambdasomewhere.👍 Thanks gang!
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.
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 😃
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!
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: https://github.com/netlify/netlify-lambda#netlify-lambda
@sw-yx I am not sure what side effects this config has.
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.
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.
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.