#Path aliases / relative imports in monorepo breaks nest start

22 messages · Page 1 of 1 (latest)

gaunt horizon
#

I'm trying to add imports from another shared project in my monorepo into my Nest.js project.

Whenever I add either a path alias or a relative import it changed the structure of the build directory from dist/src/main.js to

dist/
├─ nest-project/
│  └─ src/
│     └─ main.js
├─ shared-project/
│  └─ src/
|     └─ index.js
└─ src/
   ├─ main.js
   └─ app.controller.ts

This causes the following error when trying to run nest start

Error: Cannot find module '/Users/.../monorepo/nest-project/dist/main'

Has anyone got an idea on how the main file can be correctly found? With all my other projects this happens automatically.

gaunt horizon
gaunt horizon
#

<@&520649667684466710> Hello, my GitHub issue was recently closed and locked https://github.com/nestjs/nest/issues/13558 by member https://github.com/kamilmysliwiec I don't think Discord is a substitute for real project issues

GitHub

Is there an existing issue for this? I have searched the existing issues Current behavior When adding an external import to a Nest.js app inside a monorepo, an error occurs when running nest start:...

bright fableBOT
#

Please do not tag the moderators unless someone is breaking server rules. The mods are here to help enforce the rules of the server, and while most of them are knowledgeable about Nest, they are not the only ones able to solve your question.

potent birch
#

Your issue was closed (by the author of the framework), because it was not a framework issue, but (most likely) your setup issue - with which we, the community, try to assist with here on discord.

The issue seems to contain enough information though, that'll help us think of what might be wrong. I'm a bit busy at the moment, but I'll try to have a look later today.

#

At a first glance, the behaviour you're seeing is happening when you import files from a directory outside of the src/ - be it a config, package.json, etc.

gaunt horizon
#

Thanks for the response @potent birch the repo you sent uses Nx whilst mine is a plain pnpm workspaces monorepo

#

I have been trying to dig into this, my suspicion is that the entrypoint in nestjs is hardcoded? whilst in other frameworks it is compiled with typescript

potent birch
#

You can change entryFile using nest-cli.json: https://docs.nestjs.com/cli/monorepo#cli-properties (or using CLI arg --entryFile)

gaunt horizon
#

Is this supposed to sit in the root of my monorepo? Or inside the nest.js project?