NestJS "nest build" error TS with decorators / emitDecoratorMetadata in CI
nest build ran tsc and the compiler rejected the decorators, or compiled without emitting the type metadata Nest needs. The fix is enabling the two decorator options in tsconfig.
What this error means
nest build fails with a decorator-related "error TS" (for example TS1241 or TS1240), or the build passes but DI later fails because parameter type metadata was not emitted.
src/cats/cats.service.ts:7:3 - error TS1241: Unable to resolve signature of parameter
decorator when called as an expression.
Argument of type 'undefined' is not assignable to parameter of type 'Object'.Common causes
experimentalDecorators is not enabled
Without experimentalDecorators, tsc treats the legacy decorator syntax Nest uses as invalid and errors out.
emitDecoratorMetadata is off
Nest DI reads design-time type metadata; without emitDecoratorMetadata no metadata is emitted, so injection cannot infer types.
How to fix it
Enable both decorator options in tsconfig
- Open the
tsconfig.jsonthat nest build uses. - Set
experimentalDecoratorsandemitDecoratorMetadatato true. - Rebuild so decorators compile and metadata is emitted.
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "ES2021"
}
}Confirm nest build reads the right tsconfig
nest build uses the path in nest-cli.json; make sure it points at the tsconfig that has the decorator options.
{ "compilerOptions": { "tsConfigPath": "tsconfig.build.json" } }How to prevent it
- Keep experimentalDecorators and emitDecoratorMetadata true in every tsconfig used to build.
- Extend a single base tsconfig so build and test configs stay in sync.
- Run nest build in CI on every PR so config drift is caught early.