-
Notifications
You must be signed in to change notification settings - Fork 928
Add node.js support for Cloud Firestore (to "firebase" SDK) #221
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
Does it makes sense to post this in #198 and rename that issue instead of duplicating? |
Ahh, I scanned the issue list but missed that one. I'd rather use this as the canonical tracking bug, so I've closed #198 in favor of this. Thanks. |
SGTM 👍 |
pretty sure this webpack error is also related to the lack of universal support for the 'firebase/firestore' Cannot find module 'grpc'
Error: Cannot find module 'grpc'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/sliu/workplace/spotifly/node_modules/@firebase/firestore/dist/cjs/src/src/platform_node/grpc_connection.ts:32:14)
at Module._compile (module.js:624:30)
at Module._compile (/myproject/node_modules/source-map-support/source-map-support.js:492:25)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12) If you are using a bundler like webpack to build your client side bundle, you will need to load // since you have initialized your app somewhere above
export const getFireStore = async () => {
await import('firebase/firestore');
return firebase.firestore();
}
// and you can use it else where like
(await getFireStore()).collection('your-collection') notice I gave this example with await in ES7, but you get the idea of how you need to resolve the promise before you can proceed. |
We are building an app with Nuxt.js and facing the exact same issue. I've tried the temporary solution suggested by @goldensunliu but haven't got success. Eagerly waiting for this issue to be resolved. |
We're having the same issue trying to run tests against Firestore and our custom API wrapper using Jest. |
Im facing the exact same issue too |
Same issue too , tried @goldensunliu solution but didn't work out. Any other temporary solution ? |
+1 |
@alexandregiordanelli Also, please try to be mindful of the community rules and keep the conversation constructive. |
@adamduren It is indeed included. I believe the issue @alexandregiordanelli is facing (like the rest of us) is the one described by @goldensunliu |
Tried the solution above still getting, Error: Cannot find module 'grpc' |
* Fix miscellaneous node / GRPC bit rot. * Re-add grpc / protobufjs dependencies. * Remove crazy grpc stream error handling nonsense that is no longer necessary after grpc/grpc#9101 * Clean up grpc_connection logging (and consistently use util.inspect()). * Fix WebChannel / GRPC Connection compatibility issues. * Add an explicit mapping from "RPC name" (e.g. "BatchGetDocuments") to the REST url path (e.g. "batchGet") for WebChannel, and for GRPC just assume the first letter should be lowercased (e.g. "batchGetDocuments"). * Split Connection.invoke() into invokeRPC() and invokeStreamingRPC(), with the latter accepting a stream of results and aggregating them into an array (needed to support BatchGetDocuments RPC). * Fix serializer issues * Query limits are an 'Int32Value' but we were serializing them as a normal int which GRPC / protobufjs didn't like. * Several proto "oneof tags" were outdated. * Add build steps to copy protos into npm package. * Run integration tests for Node.JS * Added to 'test:node' script in package.json and in .vscode/launch.json * Include index.ts for browser and index.node.ts for node so the appropriate PlatformSupport gets registered. * Misc cleanup * Remove unused MockPlatform since we use the normal NodePlatform now. * Remove 'google-auth-library' CredentialsProvider that we used to use for node.js (before we were integrated with FirebaseAuth). * Fixed several tests that were hitting node.js warnings about unhandled promise failures. * mocha commmand-line args: * "--compilers ts:ts-node/register" was deprecated in favor of "--require ts-node/register" * Remove "--retries 5" when running mocha tests from VS Code. * Consistently use "--require" instead of "-r" * Add "--exit" when running from VS Code.
This issue has been closed but the problem is not resolved. I still get the error firebase.firestore is not a function. Isn't it related to this? I am using this package - https://www.npmjs.com/package/firebase - version 4.6.2 Update: After importing firebase, if I add require('firebase/firestore'), I again start getting the error - Cannot find module 'grpc' Update: I have create a stackoverflow question describing steps to replicate the issue - https://stackoverflow.com/questions/47532667/node-js-support-for-firestore-not-working |
Sorry for the confusion. This was fixed just recently and will be included in the next Firebase release. You can monitor the release notes (https://firebase.google.com/support/release-notes/js) to see when it has gone out (likely this Thursday). |
@mikelehen Thanks for clarifying. I look forward to the next release :) |
i´m using webpack and i tried this "https://github.com/liady/webpack-node-externals" and read this "https://jlongster.com/Backend-Apps-with-Webpack--Part-I" and works great |
Currently to use Cloud Firestore from node.js you can use the "firebase-admin" SDK (see node.js getting started snippets at https://firebase.google.com/docs/firestore/quickstart).
But if you want to use the "firebase" SDK instead (e.g. so you can use Firebase Authentication), you are currently out-of-luck. The "firebase" npm module will not work from node.js and you may get errors like:
This is a known issue and something we intend to address in the future.
The text was updated successfully, but these errors were encountered: