Skip to content

Decorator metadata not emitted

Quick summary

You used a decorator that relies on metadata reflection, but the compiler option is not enabled — metadata is missing at runtime.

Why this happens

  • The tsconfig.json does not have emitDecoratorMetadata: true, so type metadata is not emitted

  • The experimentalDecorators option is not enabled, which is required for decorator support

  • The reflect-metadata polyfill is not imported at the entry point before decorators are used

Minimal example

✗ Broken code
// tsconfig.json missing emitDecoratorMetadata
@Injectable()
class MyService {
  constructor(private dep: OtherService) {} // dep type metadata missing
}
✓ Fixed code
// tsconfig.json:
// { "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true } }
import 'reflect-metadata';
@Injectable()
class MyService {
  constructor(private dep: OtherService) {} // metadata available
}

Enabling emitDecoratorMetadata and importing reflect-metadata makes constructor parameter types available at runtime for dependency injection.

How to diagnose

  • Check tsconfig.json for experimentalDecorators and emitDecoratorMetadata both set to true

  • Verify that 'import reflect-metadata' is at the top of the entry file before any decorator usage

  • Log Reflect.getMetadata('design:paramtypes', target) to see if metadata is available at runtime

How to fix

  • Set experimentalDecorators: true and emitDecoratorMetadata: true in tsconfig.json

  • Import the reflect-metadata polyfill at the application entry point before any decorator code

  • If using a bundler, ensure it preserves decorator metadata and does not tree-shake reflect-metadata

How to prevent

  • Always enable both experimentalDecorators and emitDecoratorMetadata when using decorators

  • Import reflect-metadata at the entry point and ensure it is not removed by tree-shaking

Related Resources

Related Glossary

Related Lessons

← Back to language