Postgres TypeError: Converting circular structure to JSON
See original GitHub issueIssue Description
So I am using postgresql with typeorm and nestjs and I have a user entity. When I run .findOne({username })
it works fine, but doing .find({})
to get all simply gives this error:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
at JSON.stringify (<anonymous>)
at SelectQueryBuilder.<anonymous> (C:\Users\thebo\Documents\ProxyByrd\packages\backend\node_modules\.pnpm\typeorm@0.2.28\node_modules\typeorm\query-builder\SelectQueryBuilder.js:1553:67)
Expected Behavior
The following code should return the list of users to the backend:
async findAll(): Promise<User[]> {
return await this.usersRepository.find({ take: 5 });
}
Actual Behavior
It errors with circular socket structure error:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
at JSON.stringify (<anonymous>)
at SelectQueryBuilder.<anonymous> (C:\Users\thebo\Documents\ProxyByrd\packages\backend\node_modules\.pnpm\typeorm@0.2.28\node_modules\typeorm\query-builder\SelectQueryBuilder.js:1553:67)
Steps to Reproduce
- Use nestjs and typeorm
- Try to call .find({}) on an injected repository in a service.
My Environment
Dependency | Version |
---|---|
Operating System | Windows 10 |
Node.js version | 14.0.0 |
Typescript version | 4.0.5 |
TypeORM version | 0.2.28 |
Relevant Database Driver(s)
-
aurora-data-api
-
aurora-data-api-pg
-
better-sqlite3
-
cockroachdb
-
cordova
-
expo
-
mongodb
-
mysql
-
nativescript
-
oracle
- [x ]
postgres
-
react-native
-
sap
-
sqlite
-
sqlite-abstract
-
sqljs
-
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don’t know how to start. I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
TypeError: Converting Circular structure to JSON #1523 - GitHub
The TypeError: Converting circular structure to JSON shows up when you trying to JSON.stringify something which has a reference to itsself, ...
Read more >Converting circular structure to JSON at Object.stringify (native ...
I have a basic table that one my postgresql db. ... Unhandled rejection TypeError: Converting circular structure to JSON at Object.stringify ...
Read more >What is TypeError: Converting circular structure to JSON?
TypeError : Converting circular structure to JSON occurs when you try to reference your variable name within the JSON object.
Read more >Converting circular structure to JSON in nodejs-node.js
TypeError : Converting circular structure to JSON in nodejs: This error can be seen on Arangodb when using it with Node.js, because storage...
Read more >TypeError: Converting circular structure to JSON and ...
You must select a tag to post in this category. Please find the tag relating to the section of the course you are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ErolPeel When saving a One-to-Many relation in TypeORM you need to be careful to only reference one side of the relation. For example when you want to save a PartyEntity with a PartyContactEntity, do it like this:
It happens in TypeORM 0.2.22 and 0.2.18 as well. I guess, there is some modelling error on my side?