0

I have a NestJs application in which I want to use the GRPC.

To generate my typescript files from my `.proto` file I used the npm module "grpc_tools_node_protoc_ts" who generated me 2 files, "stable_pb.d.ts" and "stable_pb.d.ts".

These 2 files as well as my `.proto` file are in the same place as my controller, "src/grpc-client".

My problem is that when launching my app I keep getting the message:

[9:02:01 AM] Starting compilation in watch mode...

[9:02:05 AM] Found 0 errors. Watching for file changes.

Error: Cannot find module './stable_pb'

Require stack:

- /home/myuser/projects/myapp/dist/grpc-client/generate-image.controller.js

- /home/myuser/projects/myapp/dist/grpc-client/grpc-client.module.js

I tried several times to change the path to these .d.ts files in my controller but nothing worked.

here is the import of my controller file:

import { Controller, Get } from '@nestjs/common';
import * as grpc from '@grpc/grpc-js';
import { GenerateImageRequest, GenerateImageResponse } from './stable_pb';
import { TextToImageServiceClient } from './stable_grpc_pb';

@Controller('generate-image')
export class GenerateImageController {
  private readonly grpcClient: TextToImageServiceClient;

This is my `tsconfig.json` :

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true
  }
}

This is my `tsconfig.build.json` :

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "src/**/*.d.ts"],
  "exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

I have removed the /dist and recompiled several times already.

Does anyone have an idea to solve this "Cannot find module" problem with my configuration?

  • I specify that it is exactly the same when I change the import name in my controller by: import { GenerateImageRequest, GenerateImageResponse } from './stable_pb.d'; I receive : Error: Cannot find module './stable_pb.d' – Nejom 1er Aug 08 '23 at 07:29
  • maybe the files generated with grpc_tools_node_protoc are missing? – Yuri Golobokov Aug 09 '23 at 23:57

0 Answers0