title: TypeORM Entity Metadata not found
body: <p>Heyho,</p>
  <p>im trying to build a backend for a type of ecommerce site using NestJS + TypeORM.</p>
  <p>i need a m:n relation between my order and products table. Hovever since i need some custom fields within the pivot table i looked up typeorms documentation and as stated there i need to create a new entity which ive done. Now i get an error starting up my NestJS application:</p>
  <pre><code>Error: Entity metadata for Product#productToOrders was not found. Check if you specified a correct entity object and if it's connected in the connection options.
  </code></pre>
  <p>My product.entity.ts:</p>
  <pre class="lang-js prettyprint-override"><code>import { BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn } from &quot;typeorm&quot;;
  import { ProductToOrder } from &quot;./productToOrder.entity&quot;;
  
  @Entity()
  export class Product extends BaseEntity{
      @PrimaryGeneratedColumn()
      id: number;
      
      @Column()
      name: string;
      
      @Column()
      description: string;
      
      @Column()
      price: number;
  
      @OneToMany(type =&gt; ProductToOrder, productToOrder =&gt; productToOrder.product)
      productToOrders: ProductToOrder[];
  }
  </code></pre>
  <p>My productToOrder.entity.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { Order } from &quot;src/order/order.entity&quot;;
  import { BaseEntity, Column, Entity, ManyToOne, PrimaryGeneratedColumn } from &quot;typeorm&quot;;
  import { Product } from &quot;./product.entity&quot;;
  
  @Entity()
  export class ProductToOrder extends BaseEntity{
      @PrimaryGeneratedColumn()
      id: number;
  
      @Column()
      amount: number;
  
      @ManyToOne(() =&gt; Product, product =&gt; product.productToOrders,{eager: false})
      product: Product;
  
      @ManyToOne(() =&gt; Order, order =&gt; order.productToOrders, {eager: false})
      order: Order;
  }
  
  </code></pre>
  <p>my order.entity.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { User } from &quot;src/auth/user.entity&quot;;
  import { Product } from &quot;src/product/product.entity&quot;;
  import { ProductToOrder } from &quot;src/product/productToOrder.entity&quot;;
  import { BaseEntity, Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn } from &quot;typeorm&quot;;
  
  @Entity()
  export class Order extends BaseEntity{
      @PrimaryGeneratedColumn()
      id: number;
  
      @Column()
      ordernumber: number;
  
      @Column()
      totalprice: number;
      
      @ManyToOne(type =&gt; User, user =&gt; user.orders, {eager: false})
      user_id: User[];
  
      @OneToMany(() =&gt; ProductToOrder, productToOrder =&gt; productToOrder.order, {eager: true})
      productToOrders: ProductToOrder[];
  }
  
  </code></pre>
  <p>My directory structure:</p>
  <pre><code>src/
  ├── order
  │   ├── order.entity.ts
  │   ├── order.module.ts
  │   ├── order.service.ts
  │   ├── order.controller.ts
  │   └── order.repository.ts
  ├── product
  │   ├── product.entity.ts
  │   ├── product.module.ts
  │   ├── product.service.ts
  │   ├── product.controller.ts
  │   ├── productToOrder.entity.ts &lt;- i put the entity for the pivot table here, not sure if its right
  │   └── product.repository.ts
  └── xy
  </code></pre>
  <p>My app.module.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { TypeOrmModule } from '@nestjs/typeorm';
  import { AuthModule } from './auth/auth.module';
  import { typeOrmConfig } from './config/typeorm.config';
  import { ProductModule } from './product/product.module';
  import { OrderModule } from './order/order.module';
  
  
  @Module({
    imports: [
      TypeOrmModule.forRoot(typeOrmConfig),
      AuthModule,
      ProductModule,
      OrderModule,
    ],
    controllers: [],
    providers: [],
  })
  export class AppModule {}
  
  </code></pre>
  <p>my typeorm.config.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { TypeOrmModuleOptions } from &quot;@nestjs/typeorm&quot;;
  import * as config from 'config';
  
  const dbConfig = config.get('db');
  
  export const typeOrmConfig: TypeOrmModuleOptions = {
      type: dbConfig.type,
      host: dbConfig.host,
      port: dbConfig.port,
      username: dbConfig.username,
      password: dbConfig.password,
      database: dbConfig.database,
      autoLoadEntities: true,
      synchronize: dbConfig.synchronize,
  }
  </code></pre>
  <p>if i add the</p>
  <pre class="lang-js prettyprint-override"><code>entities: [&quot;dist/**/*.entity{.ts,.js}&quot;],
  </code></pre>
  <p>line to my typeorm.config.ts and start the application with npm run start:dev the errorcode changes to</p>
  <pre><code> TypeError: metatype is not a constructor
  </code></pre>