Robouste
Robouste

Reputation: 3680

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?

Upvotes: 10

Views: 9656

Answers (3)

Harold Mudosa
Harold Mudosa

Reputation: 1

The answer is quite straightforward, the only thing you'll need to do is to delete the "tsconfig.build.tsbuildinfo" file that get's auto-generated.

Upvotes: 0

Anh-Thi DINH
Anh-Thi DINH

Reputation: 2374

For me, delete the dist directory and run again with: npm run start:dev.

Upvotes: 0

Srevinu
Srevinu

Reputation: 424

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

Upvotes: 8

Related Questions