小编Mig*_*elo的帖子

TypeError:从具有构造函数“ClientRequest”属性“socket”的对象开始的 JSON 循环结构 -> 具有构造函数“Socket”的对象

当我尝试使用 axios 向我自己的 typeorm API 发出发布请求时,出现以下错误:

\n
TypeError: Converting circular structure to JSON\n    --> starting at object with constructor 'ClientRequest'\n    |     property 'socket' -> object with constructor 'Socket'\n    --- property '_httpMessage' closes the circle\n    at JSON.stringify (<anonymous>)\n    at stringify (C:\\Users\\Usuario\\Documents\\Manga-Api\\Manga-Api\\node_modules\\express\\lib\\response.js:1123:12)\n    at ServerResponse.json (C:\\Users\\Usuario\\Documents\\Manga-Api\\Manga-Api\\node_modules\\express\\lib\\response.js:260:14)\n    at ServerResponse.send (C:\\Users\\Usuario\\Documents\\Manga-Api\\Manga-Api\\node_modules\\express\\lib\\response.js:158:21)\n    at C:\\Users\\Usuario\\Documents\\Manga-Api\\Manga-Api\\src\\managers\\scrape.manager.ts:163:33\n    at processTicksAndRejections (node:internal/process/task_queues:93:5)\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试使用一些库来修复循环结构 JSON 并解析它,但都失败了:

\n
const safeStringify = require('json-stringify-safe');\nconst CircularJSON = require('circular-json');\n
Run Code Online (Sandbox Code Playgroud)\n

实体的关系都没有添加级联选项。

\n
await axios.post(apiName+'/object', data, { headers: { Authorization: res.req.headers.authorization } }).then(response => { res.send(response); });\n …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript typeorm

4
推荐指数
1
解决办法
9651
查看次数

标签 统计

javascript ×1

node.js ×1

typeorm ×1

typescript ×1