Nest: CacheInterceptor: Cannot read property 'applicationRef' of undefined

Created on 19 Mar 2019  路  3Comments  路  Source: nestjs/nest

I'm submitting a...


[x] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Using CacheInterceptor at global level results in following error on any route


[Nest] 69   - 03/19/2019, 10:55 AM   [ExceptionsHandler] Cannot read property 'applicationRef' of undefined +7359ms
TypeError: Cannot read property 'applicationRef' of undefined
at CacheInterceptor.trackBy (/app/node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js:45:49)
at CacheInterceptor.intercept (/app/node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js:27:26)
at /app/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:21:36
at InterceptorsConsumer.intercept (/app/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:23:24)
at /app/node_modules/@nestjs/core/router/router-execution-context.js:41:60
at /app/node_modules/@nestjs/core/router/router-proxy.js:8:23
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)

Expected behavior

No errors

Minimal reproduction of the problem with instructions

Using implementation of global cache interceptor as per docs


import * as redisStore from 'cache-manager-redis-store';
import { Module, CacheModule, CacheInterceptor } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '../../config/config.module';
import { ProductDetailModule } from '../product-detail/product-detail.module';

@Module({
  imports: [
    ConfigModule,
    ProductDetailModule,
    CacheModule.register({
      store: redisStore,
      host: 'localhost',
      port: 6379,
      ttl: 120,
      max: 50,
    }),
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_INTERCEPTOR,
      useClass: CacheInterceptor,
    },
  ],
})
export class AppModule {}

What is the motivation / use case for changing the behavior?

Environment


Nest version: 6.0.1


For Tooling issues:
- Node version: v11.9.0
- Platform:  Mac

Others:

Any help? Thanks!

Most helpful comment

Fixed in 6.0.2 :)

All 3 comments

Any news on this issue? I'm also facing this same problem

Fixed in 6.0.2 :)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mishelashala picture mishelashala  路  3Comments

marshall007 picture marshall007  路  3Comments

VRspace4 picture VRspace4  路  3Comments

cdiaz picture cdiaz  路  3Comments

cojack picture cojack  路  3Comments