nestjsgenkit

NestJS hot reload broken when calling configureGenkit


So I have a nestjs project with only one module that uses genkit in order to interact with gemini AI.

The code works correctly it breaks the hot reload.

So when I run npm run start:dev I get what is expected:

enter image description here

But after I make changes in the code, it fails to restart and I get the following:

enter image description here

I managed to pinpoint the issue to the configureGenkit call inside my service constructor. My service looks like this:

import { Injectable } from '@nestjs/common';
import { configureGenkit } from '@genkit-ai/core';
import { vertexAI } from '@genkit-ai/vertexai';

@Injectable()
export class GenkitService {
  constructor() {
    configureGenkit({
      plugins: [vertexAI({ projectId: process.env.GCP_PROJECT_ID, location: process.env.VERTEX_REGION })],
      logLevel: 'debug',
      enableTracingAndMetrics: true,
    });
  }

  // some methods

}

If I remove the configureGenkit call the hot reload works as intended again.

I figure I should call configureGenkit in a different way/place, but I'm not sure how. Any help would be appreciated.

I tried moving the configureGenkit call from the constructor to OnModuleInit but that didn't work. Also tried moving it to the boostrap function in the main.ts file, but that also failed to work.


Solution

  • I recently faced a similar problem myself, as I understand, NestJS has an issue with memory usage, it also periodically froze for me. Try to refer to this: nestjs