RepositoryNotFoundError when using HMR with TypeORM
See original GitHub issueBug Report
After following the Hot reload tutorial, then the TypeORM tutorial this error starts happening. I tried creating a new one from scratch to see if I had missed some step but the exact same error happened again. I have googled the error and none of the solutions seem to work, including the solutions talking about changing “entities” in configorm.json; I tried using sqlite and postgres but the same error happens with both.
When I run npm run build
it creates the build succesfully so I assume it has something to do with HRM or/and webpack.
Current behavior
Get this error from console: RepositoryNotFoundError: No repository for “Photo” was found. Looks like this entity is not registered in current “default” connection?
Input Code
https://github.com/Ivanca/nestjs-error-proof
Expected behavior
No errors.
Environment
Nest version: 6.5.3
For Tooling issues:
- Node version: v10.16.0
- Platform: Windows 10
Others:
Package.json contains:
"start": "ts-node -r tsconfig-paths/register dist/server",
"webpack": "webpack --config webpack.config.js",
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
See the solution here: https://github.com/nestjs/nest/issues/755
@ecSpl01t it seems that for some reasons your entities are loaded twice. Perhaps, you just have to modify your
entities
path to don’t point at both.js
and.ts
files.This issue has nothing to do with NestJS. If you use bundler like webpack with typeorm, you have to either pass class references directly (instead of using a wildcard string which - for webpack - is just a string) OR create a plugin for webpack that would replace this particular string with those references at the compilation time.