Skip to main content

v4.xv5.x

The v5 major version is backwards compatible with v4, unless you relied on the @nestjs/platform-express with manually-mounted ClsMiddleware to initialize the context.

The breaking change does not affect @nestjs/platform-fastify.

Compatibility with plugins remain unaffected and they only require a patch version bump to satisfy the peer dependency on nestjs-cls.

Changed default ClsMiddleware mount point (Express)

Since NestJS v11 now ships with Express v5, which changes the route matching algorithm, the default mount point of the ClsMiddleware was changed from '*' to '/' in v5.

If you used the automatic middleware mounting option in ClsModule.forRoot (i.e. middleware: { mount: true }), then you don't need to do anything.

If you manually mounted the middleware, you should adjust the mount point to '/' (or any other route that is relevant to you, according to the new matching algorithm).

export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ClsMiddleware)
- .forRoutes('*');
+ .forRoutes('/');
}
}