Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient pnpm monorepo setup for GraphQL and NestJS without Yarn's nohoist #1

Open
ussfranck opened this issue Aug 14, 2024 · 0 comments

Comments

@ussfranck
Copy link

Hey there ✋
In the Autospace Workshop project, at one stage of development we were obliged to change managers to solve the problem of hoisting dependencies, Yarn compared to PNPM seemed to do the trick, I've found a solution and I'd like to share it:

Configuration for a pnpm monorepo with GraphQL and NestJS

Configuration steps

1. configure dependency hoisting

Add a .npmrc file to the project root with the following contents:

shamefully-hoist=true

This configuration allows pnpm to "hoist" dependencies, making them easier to share between monorepo packages.

2. Adjust TypeScript configuration

In the tsconfig.json of each of your packages where you make calls to externals involving the creation of a node_modules folder, such as our network library, add the following configuration:

{
  "compilerOptions": {
    "paths": {
      "*": ["node_modules/*", "../../node_modules/*"]
    }
  }
}

So the final json file in my case looks like this:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*", "../../node_modules/*"]
    },
    "moduleResolution": "node",
    "esModuleInterop": true
  }
}

This configuration helps TypeScript to locate modules correctly in the monorepo structure.

Advantages of this approach

Efficiency: Works with pnpm, offering better performance and optimized use of disk space.
Simplicity: Avoids the need to manually specify which packages not to hoister.
Compatibility: Integrates well with various frameworks and libraries, including NestJS and GraphQL.

This configuration enables dependencies to be managed efficiently in a single-repo environment, without the need for specific solutions such as Yarn's "nohoist", while maintaining compatibility with frameworks such as NestJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant