Skip to main content
Version: 4.x

EXP1002: Constructor parameter type is unknown

Raised as an error, in every environment.

The container cannot tell what to inject into a constructor parameter.

Missing required @inject or @multiInject annotation in: argument 0 in class UserService.
Why: the parameter's type is not available at runtime. This build does not emit decorator metadata: tsc does when emitDecoratorMetadata is on, while tsx and esbuild do not, so the same code can work in one and fail in the other.
Fix: add @inject(<Type or token>) to argument 0 of the UserService constructor.
Code: EXP1002

There are two causes, and the Why line says which one applies:

  • The build emits no decorator metadata. tsc records constructor parameter types when emitDecoratorMetadata is on. tsx and esbuild, which expressots dev and most test runners use, do not. The same class then works after expressots build and fails in development, or the other way round.
  • The type has no runtime value. An interface, a union or any is erased by the compiler, so there is nothing to look up.

Fix​

Name what to inject on the parameter:

@provide(UserService)
export class UserService {
constructor(@inject(UserRepository) private readonly users: UserRepository) {}
}

With @inject on every constructor parameter, the class resolves the same way under every toolchain.

All codes are listed under Error responses.