Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No metadata for "User" was found using TypeOrm

Tags:

typeorm

I'm trying to get a basic setup working using TypeORM, and getting this error following the setup.

Here is a REPL (just do yarn install && yarn db:dev followed by yarn db:migrate && yarn start to reproduce the error)

Inserting a new user into the database...
{ EntityMetadataNotFound: No metadata for "User" was found.
    at new EntityMetadataNotFoundError (/Users/admin/work/typeorm-naming-strategy/src/error/EntityMetadataNotFoundError.ts:9:9)
    at Connection.getMetadata (/Users/admin/work/typeorm-naming-strategy/src/connection/Connection.ts:313:19)
    at /Users/admin/work/typeorm-naming-strategy/src/persistence/EntityPersistExecutor.ts:77:55
    at Array.forEach (<anonymous>)
    at EntityPersistExecutor.<anonymous> (/Users/admin/work/typeorm-naming-strategy/src/persistence/EntityPersistExecutor.ts:71:30)
    at step (/Users/admin/work/typeorm-naming-strategy/node_modules/typeorm/persistence/EntityPersistExecutor.js:32:23)
    at Object.next (/Users/admin/work/typeorm-naming-strategy/node_modules/typeorm/persistence/EntityPersistExecutor.js:13:53)
    at /Users/admin/work/typeorm-naming-strategy/node_modules/typeorm/persistence/EntityPersistExecutor.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/admin/work/typeorm-naming-strategy/node_modules/typeorm/persistence/EntityPersistExecutor.js:3:12)
  name: 'EntityMetadataNotFound',
  message: 'No metadata for "User" was found.' }
like image 526
ripper234 Avatar asked Jul 27 '18 16:07

ripper234


2 Answers

Adding answer bit late but its very common error.

There are two main reasons for above error. In OrmConfig,

  1. You have used *.ts instead of *.js. For example,
entities: [__dirname + '/../**/*.entity.ts']  <-- Wrong

It should be

entities: [__dirname + '/../**/*.entity.js'] 
  1. entities path is wrong. Make sure, entities path is defined according to dist folder not src folder.
like image 130
Ishraq Ahmad Avatar answered Sep 19 '22 11:09

Ishraq Ahmad


The problem is on ormConfig

Please try to use this:

entities: [__dirname + '/../**/*.entity.{js,ts}']
like image 44
Muzuri Avatar answered Sep 19 '22 11:09

Muzuri