#non-resolving imports when using dependencies between modules

2 messages · Page 1 of 1 (latest)

tulip wadi
#

Hello everyone,
I've been developing a medium complexity app for sometime now and I'm encountering some issues when trying to refactor my code, using dependencies between my level 1 modules.

I think I'm doing some kind of obvious mistake somewhere but I can not figure it out.

Here is the problem: I need to build 2 applications to deploy separately, but I want them to share a "commons" module. I am using npm workspaces to do so with 3 level 1 modules : commons, backend-profile and backend-budgeting.

My folder tree looks like this:

projetroot
|_ commons
|        |_ src
|               |_ auth
|                      |_ guards
|                              |_ jwtAuth.guard.ts
|                      |_ auth.controller.ts
|                      |_ auth.module.ts
|                      |_ auth.service.ts
|               |_ user
|                      |_ user.controller.ts
|                      |_ user.module.ts // imports the auth.module
|                      |_ user.service.ts
|        |_ package.json
|        |_ commons.module.ts
|_ backend-profile
|         |_ src
|               |_ profile
|                         |_ profile.controller.ts
|                         |_ profile.module.ts
|                         |_ profile.service.ts
|         |_ package.json // imports the commons module as a dependency - see below
|_ backend-budgeting
|         |_ src
|               |_ budgeting
|                         |_ budgeting.controller.ts
|                         |_ budgeting.module.ts
|                         |_ budgeting.service.ts
|         |_ package.json // imports the commons module as a dependency
|_package.json // defines npm workspaces 'commons' and 'backend'

In my backends package.json, I have created a dependency using npm install commons@../commons, resulting in:
backend-profile/package.json

    "commons": "file:../commons"

When I make a nest build of the commons module, everything works fine.

see next post ⏬

#

Where I'm stuck is
When I compile one of the backends whether its nest build or nest run, the commons module returns many errors for many imports of kind :

../commons/src/users/user.controller.ts:8:30 - error TS2307: Cannot find module 'src/auth/guards/jwtAuth.guard' or its corresponding type declarations.

user.controller.ts

8: import { JwtAuthGuard } from 'src/auth/guards/jwtAuth.guard';

The tree is a little complex but it did not seem very unusual to me. Can anyone point the thing I am doing wrong?