0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[TypeError: Converting circular structure to JSON] JSON.stringify()の時にエラーが出る

Last updated at Posted at 2020-11-29

コード

const params = {
  user_id: firebase.auth().currentUser.uid,
  id_token: firebase.auth().currentUser.getIdToken(false), // await が必要
}

const body = JSON.stringify(params) // エラー発生

エラー

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'C'
    |     property 'c' -> object with constructor 'C'
    |     property 'b' -> object with constructor 'zc'
    --- property 'a' closes the circle
    at JSON.stringify (<anonymous>)
    at _callee4$ (common.js?4edf:57)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)
    at Generator.eval [as next] (runtime.js?96cf:118)
    at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
    at _next (asyncToGenerator.js?1da1:25)
    at eval (asyncToGenerator.js?1da1:32)
    at new Promise (<anonymous>)
    at Object.eval (asyncToGenerator.js?1da1:21)

原因

awaitの付け忘れ。

解決コード

const params = {
  user_id: firebase.auth().currentUser.uid,
  id_token: await firebase.auth().currentUser.getIdToken(false), // awaitをつけた
}

const body = JSON.stringify(params)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?