title: EntityMetadataNotFound: No metadata for "User" was found
body: <p>PS.: I have already read a lot of similar topics, but none of them could fix my issue, already tried changing the regex pattern on entities for ormconfig.js and other stuffs.</p>
  <p>Well, a few days ago I was able to execute this ExpressJS app with success, no error was appearing. But now, it just started to throw <code>EntityMetadataNotFound: No metadata for &quot;User&quot; was found.</code>.</p>
  <p>This is the repository for the project: <a href="https://github.com/joaocasarin/gittin" rel="nofollow noreferrer">https://github.com/joaocasarin/gittin</a></p>
  <p>As you can see, My <code>entities</code> and <code>migrations</code> points to <code>dist/entities/*.js</code> and <code>dist/database/migrations/*.js</code> respectively, since I've read that TypeORM is not able to use them while in typescript (using ts-node-dev to run the app, if the entities are in .ts, I get errors saying that I can't use imports and stuffs from ES6+ on plain javascript files. And if I run migrations using the .ts files, no migrations are found to run.). Also, you'll see that I have my Entity, Repository, Service and Controller all correct (I can't see any problems with them), but still, I get that error when I try to make an interaction with the database.</p>
  <p>Insomnia request body:
  <code>/POST http://localhost:3000/api/users</code></p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;name&quot;: &quot;123&quot;,
      &quot;password&quot;: &quot;123&quot;,
      &quot;email&quot;: &quot;docker@123.com&quot;,
      &quot;admin&quot;: true
  }
  </code></pre>
  <p>response:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;error&quot;: {
      &quot;name&quot;: &quot;EntityMetadataNotFound&quot;,
      &quot;message&quot;: &quot;No metadata for \&quot;User\&quot; was found.&quot;
    }
  }
  </code></pre>
  <p>Error on terminal:</p>
  <pre class="lang-sh prettyprint-override"><code>EntityMetadataNotFound: No metadata for &quot;User&quot; was found.
      at new EntityMetadataNotFoundError (C:\Users\joaov\Documents\gittin\src\error\EntityMetadataNotFoundError.ts:10:9)
      at Connection.getMetadata (C:\Users\joaov\Documents\gittin\src\connection\Connection.ts:337:19)
      at EntityManager.getCustomRepository (C:\Users\joaov\Documents\gittin\src\entity-manager\EntityManager.ts:976:86)
      at Connection.getCustomRepository (C:\Users\joaov\Documents\gittin\src\connection\Connection.ts:372:29)
      at Object.getCustomRepository (C:\Users\joaov\Documents\gittin\src\index.ts:298:55)
      at CreateUserService.&lt;anonymous&gt; (C:\Users\joaov\Documents\gittin\src\services\CreateUserService.ts:14:37)
      at step (C:\Users\joaov\Documents\gittin\src\services\CreateUserService.ts:33:23)
      at Object.next (C:\Users\joaov\Documents\gittin\src\services\CreateUserService.ts:14:53)
      at C:\Users\joaov\Documents\gittin\src\services\CreateUserService.ts:8:71
      at new Promise (&lt;anonymous&gt;)
  </code></pre>
  <p>To make it easier, these are the relevant files that I think. Please tell me if any other file is relevant too:</p>
  <p><code>package.json</code>:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;name&quot;: &quot;gittin&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;main&quot;: &quot;./dist/index.js&quot;,
    &quot;repository&quot;: &quot;https://github.com/joaocasarin/gittin.git&quot;,
    &quot;author&quot;: &quot;Joao Casarin &lt;joaovitorcasarin@hotmail.com&gt;&quot;,
    &quot;license&quot;: &quot;MIT&quot;,
    &quot;scripts&quot;: {
      &quot;db&quot;: &quot;docker-compose -f ./docker-compose.db.yml up --build -d&quot;,
      &quot;docker:dev&quot;: &quot;docker-compose -f ./docker-compose.dev.yml up --build -d&quot;,
      &quot;docker:prod&quot;: &quot;docker-compose -f ./docker-compose.yml up --build -d&quot;,
      &quot;docker:clear&quot;: &quot;docker-compose down -v --rmi local&quot;,
      &quot;docker:stop&quot;: &quot;docker-compose down&quot;,
      &quot;dev&quot;: &quot;ts-node-dev ./src/index.ts&quot;,
      &quot;test&quot;: &quot;jest&quot;,
      &quot;migration:run&quot;: &quot;ts-node-dev ./node_modules/typeorm/cli.js migration:run&quot;,
      &quot;migration:create&quot;: &quot;ts-node-dev ./node_modules/typeorm/cli.js migration:create&quot;,
      &quot;entity:create&quot;: &quot;ts-node-dev ./node_modules/typeorm/cli.js entity:create&quot;,
      &quot;build&quot;: &quot;tsc&quot;,
      &quot;start&quot;: &quot;node .&quot;
    },
    &quot;dependencies&quot;: {
      &quot;axios&quot;: &quot;^0.21.1&quot;,
      &quot;bcryptjs&quot;: &quot;^2.4.3&quot;,
      &quot;class-transformer&quot;: &quot;^0.4.0&quot;,
      &quot;cors&quot;: &quot;^2.8.5&quot;,
      &quot;dotenv&quot;: &quot;^10.0.0&quot;,
      &quot;express&quot;: &quot;^4.17.1&quot;,
      &quot;express-async-errors&quot;: &quot;^3.1.1&quot;,
      &quot;jsonwebtoken&quot;: &quot;^8.5.1&quot;,
      &quot;pg&quot;: &quot;^8.6.0&quot;,
      &quot;reflect-metadata&quot;: &quot;^0.1.13&quot;,
      &quot;typeorm&quot;: &quot;^0.2.34&quot;,
      &quot;uuid&quot;: &quot;^8.3.2&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@types/babel__core&quot;: &quot;^7.1.15&quot;,
      &quot;@types/bcryptjs&quot;: &quot;^2.4.2&quot;,
      &quot;@types/cors&quot;: &quot;^2.8.10&quot;,
      &quot;@types/express&quot;: &quot;^4.17.12&quot;,
      &quot;@types/jest&quot;: &quot;^26.0.23&quot;,
      &quot;@types/jsonwebtoken&quot;: &quot;^8.5.4&quot;,
      &quot;@types/node&quot;: &quot;^15.12.4&quot;,
      &quot;@types/supertest&quot;: &quot;^2.0.11&quot;,
      &quot;@types/uuid&quot;: &quot;^8.3.1&quot;,
      &quot;jest&quot;: &quot;^27.0.5&quot;,
      &quot;supertest&quot;: &quot;^6.1.3&quot;,
      &quot;ts-jest&quot;: &quot;^27.0.3&quot;,
      &quot;ts-node-dev&quot;: &quot;^1.1.6&quot;,
      &quot;typescript&quot;: &quot;^4.3.4&quot;
    }
  }
  </code></pre>
  <p><code>ormconfig.js</code>:</p>
  <pre class="lang-js prettyprint-override"><code>module.exports = {
      &quot;type&quot;: &quot;postgres&quot;,
      &quot;ssl&quot;: process.env.NODE_ENV === 'production'
             &amp;&amp; process.env.DATABASE_URL !== 'postgres://postgres:docker@localhost:5432/gittin'
             &amp;&amp; process.env.DATABASE_URL !== 'postgres://postgres:docker@db:5432/gittin' ? { rejectUnauthorized: false } : false,
  
      &quot;url&quot;: process.env.DATABASE_URL,
      
      &quot;entities&quot;: [&quot;dist/entities/*.js&quot;], // typeorm loads entities from this directory
      &quot;migrations&quot;: [&quot;dist/database/migrations/*.js&quot;], // typeorm loads migrations from the directory
  
      &quot;dropSchema&quot;: process.env.NODE_ENV === 'test' ? true : false,
      &quot;migrationsRun&quot;: process.env.NODE_ENV !== 'production' ? true : false,
  
      &quot;cli&quot;: {
          &quot;migrationsDir&quot;: &quot;src/database/migrations&quot;, // typeorm creates migrations in this directory
          &quot;entitiesDir&quot;: &quot;src/entities&quot; // typeorm creates entities in this directory
      }
  }
  </code></pre>
  <p><code>src/entities/User.ts</code>:</p>
  <pre><code>import { Entity, PrimaryColumn, Column, CreateDateColumn, UpdateDateColumn } from &quot;typeorm&quot;;
  import { Exclude } from &quot;class-transformer&quot;;
  import { v4 as uuid } from &quot;uuid&quot;;
  
  @Entity(&quot;users&quot;)
  class User {
  
      @PrimaryColumn()
      readonly id: string;
  
      @Column()
      name: string;
  
      @Column()
      email: string;
  
      @Column()
      admin: boolean;
  
      @Exclude()
      @Column()
      password: string;
  
      @CreateDateColumn()
      created_at: Date;
  
      @UpdateDateColumn()
      updated_at: Date;
  
      constructor() {
          if (!this.id) {
              this.id = uuid();
          }
      }
  }
  
  export { User };
  </code></pre>
  <p><code>src/repositories/UserRepositories.ts</code>:</p>
  <pre><code>import { EntityRepository, Repository } from &quot;typeorm&quot;;
  import { User } from &quot;../entities/User&quot;;
  
  @EntityRepository(User)
  class UsersRepositories extends Repository&lt;User&gt; {}
  
  export { UsersRepositories };
  </code></pre>
  <p><code>src/services/CreateUserService.ts</code>:</p>
  <pre><code>import { getCustomRepository } from &quot;typeorm&quot;;
  import { UsersRepositories } from &quot;../repositories/UsersRepositories&quot;;
  import { hash } from &quot;bcryptjs&quot;;
  
  interface IUserRequest {
      name: string;
      email: string;
      admin?: boolean;
      password: string;
  }
  
  class CreateUserService {
      async execute({ name, email, admin = false, password }: IUserRequest) {
              const usersRepository = getCustomRepository(UsersRepositories);
  
              if(!email) {
                  throw new Error('Incorrect e-mail.');
              }
  
              const userAlreadyExists = await usersRepository.findOne({ email });
  
              if(userAlreadyExists) {
                  throw new Error('User already exists.');
              }
  
              const passwordHash = await hash(password, 8);
  
              const user = usersRepository.create({ name, email, admin, password: passwordHash });
  
              await usersRepository.save(user);
  
              return user;
      }
  }
  
  export { CreateUserService };
  </code></pre>
  <p><code>src/controllers/CreateUserController.ts</code>:</p>
  <pre><code>import { Request, Response } from &quot;express&quot;;
  import { CreateUserService } from &quot;../services/CreateUserService&quot;;
  
  class CreateUserController {
      async handle(request: Request, response: Response) {
          try {
              const { name, email, admin, password } = request.body;
  
              const createUserService = new CreateUserService();
  
              const user = await createUserService.execute({ name, email, admin, password });
  
              return response.send(user);
          } catch (error) {
              return response.send({ error });
          }
      }
  }
  
  export { CreateUserController };
  </code></pre>
  <p><code>src/routes/index.ts</code>:</p>
  <pre><code>import { Router, Request, Response, NextFunction } from &quot;express&quot;;
  import { CreateUserController } from &quot;../controllers/CreateUserController&quot;;
  
  const router = Router();
  
  const createUserController = new CreateUserController();
  router.post('/users', createUserController.handle);
  
  export default router;
  </code></pre>