typescriptnestjs

Nestjs - Cannot find module dist\main


I'm using nestjs. I have a front application so I've decided to create a "common" folder for both front and back:

    project  
    │
    └───common
    │   │
    │   └───dtos
    │       │   dto-a.ts
    │       │   dto-b.ts
    │   
    └───api  (==> nestjs)
    │   │
    │   └───src
    │
    └───front
        │
        └───src

In both front and back, I have added this to tsconfig:

{
  "compilerOptions": {
    "paths": {
      "@common/*": ["../common/*"]
    }
  }
}

So I can use my models like this:


import { DtoA} from "@common/dtos";

However, since I made the change, the compilation is creating two folder under the dist folder:

    dist
    │
    └───common
    │   
    └───api

Nestjs tries to find something into dist/main, and fails:

Error: Cannot find module 'path\to\project\api\dist\main' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1039:15) at Function.Module._load (node:internal/modules/cjs/loader:885:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47

How can I tell nestjs to look into dist/api/main, or how can I bundle the common folder inside the api build?


Solution

  • It needed to add to the nest-cli the "entryFile" key. example: "entryFile": "./apps/users/src/main.js",