question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] TypeORM repositories are not initialized in some situations

See original GitHub issue

Information

Example

  1. Build environment for testing
    git clone https://github.com/yuki-takei/tsed-typeorm-undefined-repository.git
    cd tsed-typeorm-undefined-repository
    yarn
    
  2. Modify src/index.ts and switch server modules
    • You can switch 3 kinds of servers. Activate one of them.
      import {Server} from "./server-works-well";
      // import {Server} from "./server-not-work1";  // without name property
      // import {Server} from "./server-not-work2";  // without $onReady() process
      
  3. Launch server
    yarn dev
    
  4. Go to http://localhost:8080/hello

What happens?

  • src/server-works-well.ts
    • This works fine. UserRepository instance will be initialized correctly and you will see the message User count is 0
  • src/server-not-work1.ts
    • UserRepository instance will not be initialized.
    • The server returns 500 with the message Cannot read property 'count' of undefined
  • src/server-not-work2.ts
    • UserRepository instance will not be initialized.
    • The server returns 500 with the message Cannot read property 'count' of undefined

What is the expected result?

  • UserRepository instance will be initialized correctly even without name property in ConnectionOptions or without this.injector.get<TypeORMService>(TypeORMService); process.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Romakitacommented, May 11, 2021

I sent you a PR. You’ve missed the import of typeorm. It’s really important to keep it.

import {Configuration} from "@tsed/common";
import "@tsed/platform-express";
import "@tsed/typeorm"; // !!! IMPORTANT TO ADD THIS !!!

I added a warning on the documentation: https://tsed.io/tutorials/typeorm.html#installation

See you Romain

1reaction
yuki-takeicommented, Apr 6, 2021

@Romakita Hi. I made #1334. Please review it and feedback.

Regards,

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typesafe entity initialization does not work with TypeOrm 0.3.6
Having any entity that uses a constructor while using the latest version of TypeOrm (0.3.6) will trigger the bug while the database ...
Read more >
Connection "default" was not found with TypeORM
You are trying to create a repository or manager without the connection being established. Try doing this const shopkeeperRepository ...
Read more >
no metadata for - You.com | The AI Search Engine You Control
Am I doing something wrong or is there a bug in typeorm? Open side panel. NestJS EntityMetadataNotFoundError: No metadata for "Repository" was found....
Read more >
TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
Supports both DataMapper and ActiveRecord (your choice). Entities and columns. Database-specific column types. Entity manager. Repositories and custom ...
Read more >
NestJS, TypeORM and PostgreSQL — full example ... - Medium
In this example we'll work on a simple NodeJS API that is powered by a PostgreSQL database for data storage and setup some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found