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
- Change the glob to match both compiled and source extensions.
- Or import entity classes explicitly into the entities array.
- 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
.tsand.jsextensions. - Run the compiled build in CI, not ts-node, so glob issues surface.
Related guides
NestJS "TypeOrmModule ... connection ECONNREFUSED" in CIFix NestJS TypeOrmModule "connect ECONNREFUSED" in CI - the database service is not reachable at bootstrap be…
NestJS "Nest application failed to start" in CIFix "Error: Nest application failed to start" in CI - a lifecycle hook, module init, or async provider threw…
NestJS jest "Cannot find module '@app/...'" path alias (moduleNameMapper) in CIFix NestJS jest "Cannot find module '@app/...'" in CI - tsconfig path aliases are not mapped in jest, so add…