Skip to content
Latchkey

NestJS TypeORM "No metadata for X was found" (entity glob) in CI

TypeORM found no entity metadata because its entities glob pointed at .ts files under src, but the compiled build runs .js files under dist. The glob matched nothing at runtime.

What this error means

The app runs fine locally with ts-node but fails after nest build with "EntityMetadataNotFoundError: No metadata for 'User' was found." in CI.

NestJS
EntityMetadataNotFoundError: No metadata for "User" was found.
    at DataSource.getMetadata (/app/dist/node_modules/typeorm/data-source/DataSource.js:...)

Common causes

The entities glob targets src/.ts, not dist/.js

A glob like src/**/*.entity.ts matches during local ts-node runs but nothing after compilation, where files are dist/**/*.entity.js.

Entities are not explicitly registered

Relying on a glob that does not survive the build, with no explicit entity list, leaves TypeORM with no metadata.

How to fix it

Use a build-safe glob or import entities

  1. Change the glob to match both compiled and source extensions.
  2. Or import entity classes explicitly into the entities array.
  3. Rebuild and run from dist to confirm metadata loads.
app.module.ts
TypeOrmModule.forRoot({
  entities: [__dirname + '/**/*.entity{.ts,.js}'],
})

Register entities explicitly per feature

List entities directly so no glob has to match the compiled layout.

users.module.ts
TypeOrmModule.forFeature([User, Order])

How to prevent it

  • Prefer explicit entity imports over globs that break after compilation.
  • If using a glob, include both .ts and .js extensions.
  • Run the compiled build in CI, not ts-node, so glob issues surface.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →