typeorm: ts-node throwing RepositoryNotFoundError
Here is the example repo. https://github.com/zackarychapple/flagger
When I am starting the server with nodemon everything initializes correctly however when seed tries to run it bombs out with the below error. I tried several paths for mapping to my entities however it seems none of them pick up. Any thoughts?
(node:99829) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RepositoryNotFoundError: No repository for "FlagsEntity" was found. Looks like this entity is not registered in current "default" connection?
(node:99829) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (3 by maintainers)
I also had the same
No repository for ... in current "default" connectionand it worked fine for development (running with nodemon), but failed after tsc compilation running under node. I had to change:to:
I see a reference to this in the typeorm docs, is this the prescribed way for dealing with entities in typescript? (https://typeorm.github.io/connection.html#creating-connection)
no, it depends how you run your app. If you are running via
ts-nodethen you can use “.ts” files as entities. If you aren’t usingts-nodethen you must specify “.js” files. And you need to make sure to specify proper output directory (if you are using outDir tsc option) to ensure paths to your generated js files are correct.I can’t find any
*.entity.tsin the folder where this file (flags.database.config.ts) exists. It cannot grab your entities if the files they live in do not match the pattern you’ve specified.It worked for me:
@chriszrc Prove me wrong but I think it worked when I totally omitted the file extension and simply wrote
@apologetics you’re right. The globber was not matching what I expected.
__dirname + '/../*/*.entity.ts'is what got it to work for me. Thank you for your help.first, you don’t need
TypeOrmDatabaseServiceextra wrapper - typeorm already has everything you do and you just create extra redundant layer. Second, better if you’ll use single ormconfig.json file and store your connection settings there. Third, create connection in your app bootstrap file, in a place likeserver.ts.And regarding your problem - as @apologetics told you the problem in
__dirname + '/*.entity.ts'- it does not point to any file, make sure your path are really point to entities.Finally I can use official nest new project’s
npm run start:devandnpm run build > cd dist > node mainafter change the ormconfig.jsno
SyntaxError: Unexpected token importand noLooks like this entity is not registered in current ...i found error it says that
cannot find name __dirnamewhat is that means?