1

I have a nest app that is using monorepo mode. I would like to take advantage of the new repl feature that was released in nest 9.0+.

My directory structure looks as such:

apps/

--inventory-ops/src/app.module

--ticket-office/src/app.module

I have followed the instructions found in the docs creating a repl.ts, but when I run the repl commannd:

npm run start -- --entryFile repl

I get this error output:

Error: Cannot find module '/dist/apps/ticket-office/repl'

Looking at my dist folder, the only build target is main.js, which would explain it not being able to find the repl module. Do I need to update something in my webpack config to make sure repl.ts gets built as well? Any help would be appreciated.

Paul T
  • 1,455
  • 11
  • 15

1 Answers1

2

I managed to solve this by adding a new project in nest-cli.json, for example:

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "apps/gateway/src",
  "monorepo": true,
  "root": "apps/gateway",
  "compilerOptions": {
    "webpack": true,
    "tsConfigPath": "apps/gateway/tsconfig.app.json"
  },
  "projects": {
    "gateway": {
      "type": "application",
      "root": "apps/gateway",
      "entryFile": "main",
      "sourceRoot": "apps/gateway/src",
      "compilerOptions": {
        "tsConfigPath": "apps/gateway/tsconfig.app.json"
      }
    },
    "ticket-office": {
      "type": "application",
      "root": "apps/ticket-office",
      "entryFile": "main",
      "sourceRoot": "apps/ticket-office/src",
      "compilerOptions": {
        "tsConfigPath": "apps/ticket-office/tsconfig.app.json"
      }
    },
    "ticket-office:repl": { // <<--- HERE
      "type": "application",
      "root": "apps/ticket-office",
      "entryFile": "repl", // <<-- HERE
      "sourceRoot": "apps/ticket-office/src",
      "compilerOptions": {
        "tsConfigPath": "apps/ticket-office/tsconfig.app.json"
      }
    },
  }
}

Then you can run nest start ticket-office:repl

I hope this helps.

EDIT: Adapted the answer to your question.