简体   繁体   English

JSON.stringify 在 Angular Universal 中的 SSR 期间抛出错误但适用于 locahost “TypeError: Converting circle structure to JSON”

[英]JSON.stringify throws error during SSR in Angular Universal BUT works on locahost "TypeError: Converting circular structure to JSON"

I have the following in my angular component我的角度组件中有以下内容

JSON.stringify({ "webSlug": slug });

that works fine on localhost when serving the app with ng serve , but when universal tries to server-side render on a node app.当使用ng serve应用程序提供ng serve ,它在 localhost 上工作正常,但是当通用尝试在节点应用程序上进行服务器端渲染时。 The server console shows the following error... How can i rewrite this or resolve the error?服务器控制台显示以下错误...我该如何重写或解决错误?

ERROR { TypeError: Converting circular structure to JSON
0|amec  |     at JSON.stringify (<anonymous>)
0|amec  |     at readableObjectToString (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:669:63)
0|amec  |     at resolvePromise (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:831:69)
0|amec  |     at resolvePromise (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:788:17)
0|amec  |     at /home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:892:17
0|amec  |     at ZoneDelegate.invokeTask (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:423:31)
0|amec  |     at Object.onInvokeTask (/home/ec2-user/packages/core/src/zone/ng_zone.ts:262:25)
0|amec  |     at ZoneDelegate.invokeTask (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:422:60)
0|amec  |     at Zone.runTask (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:195:47)
0|amec  |     at drainMicroTaskQueue (/home/ec2-user/amec_compiled/node_modules/zone.js/dist/zone-node.js:601:35)
0|amec  |   rejection: 
0|amec  |    HttpErrorResponse {
0|amec  |      headers: HttpHeaders { normalizedNames: Map {}, lazyUpdate: null, headers: Map {} },
0|amec  |      status: 0,
0|amec  |      statusText: 'Unknown Error',
0|amec  |      url: null,
0|amec  |      ok: false,
0|amec  |      name: 'HttpErrorResponse',
0|amec  |      message: 'Http failure response for (unknown url): 0 Unknown Error',
0|amec  |      error: 
0|amec  |       ProgressEvent {
0|amec  |         type: 'error',
0|amec  |         target: [XMLHttpRequest],
0|amec  |         currentTarget

I had that error once, and the cause was actually a HTTP request sent by angular universal was unsuccessful.我曾经遇到过那个错误,原因实际上是 angular Universal 发送的 HTTP 请求不成功。 So the part about converting a circular structure to json was misleading.因此,将循环结构转换为 json 的部分具有误导性。

I think it's the same for you here, based on the following message根据以下消息,我认为这对您来说也是一样

message: 'Http failure response for (unknown url): 0 Unknown Error',

Make sure that angular universal can send requests to your API or whatever url you are calling.确保 angular Universal 可以向您的 API 或您正在调用的任何 url 发送请求。 It can just be that the SSL certificate of the target server is invalid (if I remember correctly, that was my problem)可能只是目标服务器的 SSL 证书无效(如果我没记错的话,那是我的问题)

I had the same issue.我遇到过同样的问题。 As @David said, The issue was due to the locally generated SSL certificate.正如@David 所说,问题是由于本地生成的 SSL 证书造成的。 When you run in the browser (ng serve), the local SSL certificate is already trusted and won't be an issue.当您在浏览器中运行 (ng serve) 时,本地 SSL 证书已受信任,不会成为问题。 But for the SSR certificate is not valid.但是对于SSR证书是无效的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过JSON.stringify()将循环结构转换为JSON - Converting circular structure to JSON at JSON.stringify () Angular5 Universal:将圆形结构转换为JSON - Angular5 Universal: Converting circular structure to JSON Angular-TypeError:将圆形结构转换为JSON - Angular - TypeError: Converting circular structure to JSON TypeError:将圆形结构转换为JSON angular 6 - typeerror: converting circular structure to json angular 6 Angular Json Pipe 类型错误:将循环结构转换为 Z0ECD11C1D7A287401D148A23BBDZ - Angular Json Pipe TypeError: Converting circular structure to JSON 未捕获的类型错误:在 Angular / 依赖项更新后将循环结构转换为 JSON - Uncaught TypeError: Converting circular structure to JSON after Angular / dependencies update UnhandledPromiseRejectionWarning: TypeError: 使用 Jest + Angular 将循环结构转换为 JSON - UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON with Jest + Angular Angular FormControl Jest 测试导致 TypeError:将循环结构转换为 JSON - Angular FormControl Jest test causing TypeError: Converting circular structure to JSON 错误类型错误:将循环结构转换为 JSON --> 从 object 开始,构造函数为“FirebaseAppImpl” Firebase Angular - ERROR TypeError: Converting circular structure to JSON --> starting at object with constructor 'FirebaseAppImpl' Firebase Angular 为使用 routerLink、Spectator 和 Jest 的角度组件编写测试时出现 `TypeError:将循环结构转换为 JSON` 错误 - `TypeError: Converting circular structure to JSON` error when writing tests for an angular component that utilizes routerLink, Spectator, and Jest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM