Managing dependencies in a shared package

15 Views Asked by At

I'm facing an issue with managing dependencies in a NestJS project where I have multiple APIs. My goal is to centralize all dependencies in a shared module (api-common) and then use this shared module in other APIs without having to install dependencies separately for each API.

Here's my project structure:

- api-common
  - package.json
  - tsconfig.json
  - node_modules
    - @nestjs
      - common
      - other_modules

- api-admin
  - package.json
  - tsconfig.json
  - node_modules
    - @client
      - api-common (linked using file:../api-common)

- api-freeman
  - package.json
  - tsconfig.json
  - node_modules
    - @client
      - api-common (linked using file:../api-common)

In both api-admin and api-freeman, I've linked api-common using "@client/api-common": "file:../api-common" in package.json. The api-common project contains various dependencies, including @nestjs/common.

However, when I try to import modules from @nestjs/common in my api-admin or api-other projects, I'm getting errors like "Cannot find module '@nestjs/common' or its corresponding type declarations".

I've already verified that @nestjs/common is installed in the node_modules of api-common.

I'm using pnpm as my package manager.

0

There are 0 best solutions below