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

TypeError: entry.toJSON is not a function #1102

Closed
deepak786 opened this issue May 9, 2022 · 8 comments · Fixed by #1125
Closed

TypeError: entry.toJSON is not a function #1102

deepak786 opened this issue May 9, 2022 · 8 comments · Fixed by #1125
Assignees

Comments

@deepak786
Copy link

Getting the below error in the trigger functions.auth.user().onDelete

TypeError: entry.toJSON is not a function
   at /workspace/node_modules/firebase-functions/lib/common/providers/identity.js:113:70
   at Array.map (<anonymous>) 
   at Object.record.toJSON (/workspace/node_modules/firebase-functions/lib/common/providers/identity.js:113:49)
   at JSON.stringify (<anonymous>) 
   at onUserDeleted (/workspace/user_deleted/index.js:13:59) 
   at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:135:23)
   at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:144:25
   at processTicksAndRejections (internal/process/task_queues.js:97:5) 

cloud function trigger

exports.goodByeUser = functions.auth.user().onDelete((user) => {
  console.log(`deleting data of user ${JSON.stringify(user)}`); // this JSON.stringify gives the error
});

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "aws-sdk": "^2.658.0",
    "axios": "^0.21.1",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "currencyformatter.js": "^2.2.0",
    "express": "^4.17.1",
    "firebase-admin": "^10.2.0",
    "firebase-functions": "^3.21.0",
    "jsonexport": "^3.0.1",
    "moment": "^2.24.0",
    "nanoid": "^3.0.2",
    "request": "^2.88.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1"
  },
  "private": true,
  "engines": {
    "node": "12"
  }
}

This was working fine with the below configuration:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "aws-sdk": "^2.658.0",
    "axios": "^0.21.1",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "currencyformatter.js": "^2.2.0",
    "express": "^4.17.1",
    "firebase-admin": "^9.11.0",
    "firebase-functions": "^3.14.1",
    "jsonexport": "^3.0.1",
    "moment": "^2.24.0",
    "nanoid": "^3.0.2",
    "request": "^2.88.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1"
  },
  "private": true,
  "engines": {
    "node": "10"
  }
}

I updated the firebase-admin and firebase-functions dependencies and updated the Node environment to 12.

@colerogers
Copy link
Contributor

Apologies, it seems when we upgraded a module from lodash we didn't re-implement toJSON fully. Thanks for catching this!

@deepak786
Copy link
Author

@colerogers Now I have to wait for the new release, right?

@colerogers
Copy link
Contributor

@deepak786 That's correct, we'll work on cutting a release soon.

@deepak786
Copy link
Author

Thank You @colerogers

@avi-l
Copy link

avi-l commented May 17, 2022

Is there a workaround? What version do I need to install in order to make this function work?

exports.newUser = functions.auth.user().onCreate((user) => {
  return db
      .collection("user")
      .doc(user.uid)
      .create(JSON.parse(JSON.stringify(user)));
});

@colerogers
Copy link
Contributor

We just released v3.21.2 which contains the fix.

@avi-l
Copy link

avi-l commented May 18, 2022

Great! It's working now, thank you. and thanks @deepak786 for reporting the issue.

@puf
Copy link

puf commented Oct 11, 2022 via email

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

Successfully merging a pull request may close this issue.

5 participants