[英]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.