Skip to content

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: k.setTimeout is not a function #198

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

Closed
mdrideout opened this issue Oct 9, 2017 · 11 comments

Comments

@mdrideout
Copy link

mdrideout commented Oct 9, 2017

[REQUIRED] Describe your environment

  • Operating System version: macOS Sierra 10.12.6
  • Firebase SDK version: 4.5.0
  • Firebase Product: firestore

[REQUIRED] Describe the problem

Using the Quickstart code for "web", copying and pasting the exact code from the tutorial, I get the error
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: k.setTimeout is not a function

I do not receive this error when using the node.js example code - however, that uses the npm install --save firebase-admin@^5.4.0 package, and a service account.

I did not have issues with the realtime database trying to accomplish almost the exact same tasks.

Steps to reproduce:

The Cloud Firestore SDK is also available as an npm package.
npm install [email protected] --save

You'll need to manually require both Firebase and Cloud Firestore.

const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");

Initialize the firestore (using firebase API information) - note that the persistence example code is deprecated, and can be omitted - omitting does not resolve the issue. The console will output the updated code for this feature - however, that does not resolve the issue.

firebase.initializeApp({
    apiKey: '### FIREBASE API KEY ###',
    authDomain: '### FIREBASE AUTH DOMAIN ###',
    projectId: '### CLOUD FIRESTORE PROJECT ID ###'
  });

  firebase.firestore().settings({
    // Enable offline support
    persistence: true
  });

  // Initialize Cloud Firestore through firebase
  var db = firebase.firestore();

Try this code to add a document

db.collection("users").add({
    first: "Ada",
    last: "Lovelace",
    born: 1815
})
.then(function(docRef) {
    console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
    console.error("Error adding document: ", error);
});
@toddgeist
Copy link

@boon4376 wondering if you are using next.js or some other SSR node framework?

I am getting this error with Next.js, but only when the code renders server side. If load it only client side I get no errors.

@Purii
Copy link

Purii commented Oct 12, 2017

I get the same error, but with micro / micro-dev.

@toddgeist
Copy link

@Purii that would make sense, if I am right in guessing that the "web" library is browser only at this point. It isn't meant to run on node.js.

@Purii
Copy link

Purii commented Oct 12, 2017

@toddgeist That's right. But I used the realtime database also with the client sdk, because I don't need the additional features of the admin sdk

@mdrideout
Copy link
Author

I'm relatively new to node.js - I get this error running the script file on command line on my mac (have not tested in browser). No other frameworks in use - no express server or anything like that setup.

I used the realtime database in the same way without issue so just expected the firestore to also work that way.

@mikelehen
Copy link
Contributor

To use Cloud Firestore from node.js you must currently use the firebase-admin SDK (and follow the "node.js" quickstart on https://firebase.google.com/docs/firestore/quickstart). The "firebase" SDK currently cannot be used to access Cloud Firestore on Node.JS. Only web is supported right now. We plan to make this work in the future though, see #221 for details.

@jbeckton
Copy link

I am having this issue as well but I am using the admin SDK as @mikelehen mentioned.

@mikelehen
Copy link
Contributor

Just as an update, #221 was resolved quite a while ago and we actually support node.js from the non-admin Firebase SDK now so this issue is completely obsolete.

@jbeckton Can you please open a new issue with details (your code, the exact error you're getting, etc.)? If you're using the admin SDK then you're using the nodejs-firestore module and you should open the issue over here: https://github.com/googleapis/nodejs-firestore/issues

@jbeckton
Copy link

@mikelehen Thanks for the update, I was actually wondering if the non admin sdk would work in node.js (Firebase Functions). In my search I have found a fair number of postings about developers have issues with them so I was planning to avoid and use the admin SDK.

I already posted an issue with the admin sdk project but it sounds like I should move it to the nodejs-firestore project.

@mikelehen
Copy link
Contributor

Functions is integrated with the admin SDK so that's going to be the path of least resistance. That said, in theory, I think you could pull in the non-admin SDK. But you'd need to manually initialize it and authenticate it, etc. If you're going that route, I'd be curious to know why.

@jbeckton
Copy link

@mikelehen It had crossed my mind to use the non admin SDK in the functions but I felt like that was probably not it's intended use and probably not the best route. I wanted to use custom tokens and for auth I did not want to rely on the firebase client libraries since I am building an Angular Universal app and the AngularFire2 library does not seem to be fully supportive of this set up just yet. What I have decided to do is use custom tokens and the firebase RESTful auth endpoint so that I can authenticate in the server side functions and pass a token back to the client, this is more inline with what I usually do. The token will be persisted in the browser storage and sent back to the functions on each request. As for the client libraries I can use the token to log the user into Firebase when the app is running in the browser.

@firebase firebase locked and limited conversation to collaborators Oct 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants