Instead of creating a massive, duplicated node_modules folder for every single project, pnpm uses a global store on your machine. When you install dependencies, it creates hard links to the global store and symlinks within your project. This means if you have ten Angular projects using the same version of @angular/core, that package is only saved on your disk once.
Here is how you can get started and integrate it smoothly with Angular, along with some modern best practices.
1. Installation
If you don’t already have pnpm installed globally, you can do so using npm (ironically):
npm install -g pnpm
2. Creating a New Angular Project
The Angular CLI makes it incredibly simple to specify your preferred package manager right from the start. You don’t need to create the project with npm and then migrate it.
To generate a new Angular workspace and tell the CLI to use pnpm for all dependency installations, use the --package-manager flag:
ng new my-angular-app --package-manager=pnpm
What this does:
- Generates the standard Angular boilerplate.
- Uses
pnpm installinstead ofnpm installunder the hood. - Generates a
pnpm-lock.yamlfile instead ofpackage-lock.json. - Automatically updates your
angular.jsonfile so that future CLI commands (like adding libraries) know to usepnpm.
3. Angular + pnpm Best Practices for 2026
Once your project is up and running, keep these modern practices in mind to ensure your codebase stays clean, scalable, and performant.
Architecture & Structure
- Embrace the New Naming Conventions: If you are using Angular 17+ or newer, lean into the concise file naming styles (e.g.,
app.tsinstead ofapp.component.ts) if your team agrees on it, as the CLI now offers style guide options. - Lazy Loading is Mandatory: For enterprise apps, never load everything upfront. Use
ng generate module ... --route ...to establish lazy-loaded feature modules early. - Singleton Services in Core: Keep services that need to be instantiated only once (like authentication or global state) in a
core/folder.
Performance & Coding Standards
- Strict Typing: Maintain the default strict mode enabled during
ng new(--strict=true). Use TypeScript interfaces to enforce data contracts and prevent object shape errors. - Always use
trackBywith*ngFor: If you are iterating over lists, always provide atrackByfunction (preferring a unique ID likeitem.idover the array index). This prevents Angular from destroying and recreating DOM nodes unnecessarily. - Modern ES6+ Syntax: Utilize arrow functions for clean
thisbinding, object destructuring, and template literals to keep your component logic readable.
State Management
- Choose the Right Tool: As your app grows, you’ll need state management. If you have highly complex state interactions and need time-travel debugging, look into NgRx. If you want something with less boilerplate that feels more natively “Angular,” consider NGXS.
Migrating an existing Angular project from npm or yarn to pnpm is a straightforward process, but it requires a few specific steps to ensure your lockfiles and Angular CLI configurations are updated correctly.
Here is a step-by-step guide to making the switch.
1. Install pnpm
If you haven’t already, install pnpm globally. You can do this using npm:
npm install -g pnpm
2. Update Angular CLI Configuration
You need to tell the Angular CLI to use pnpm as the default package manager for this specific workspace. This ensures that when you run commands like ng add or ng update, the CLI uses pnpm under the hood.
Run this command in the root of your Angular project:
ng config cli.packageManager pnpm
This will automatically update your angular.json file with the following configuration:
"cli": {
"packageManager": "pnpm"
}
3. Remove Old Files
Before generating the new pnpm lockfile, you need to clean up the artifacts left behind by your previous package manager.
Delete the existing node_modules folder and your old lockfile:
- If you used npm: Delete
node_modulesandpackage-lock.json. - If you used yarn: Delete
node_modulesandyarn.lock.
Note: You can delete these manually, or use a tool like npkill to quickly remove node_modules.
4. Import the Lockfile (Optional but Recommended)
If you want to maintain the exact dependency versions you had before (which is highly recommended to avoid unexpected breaking changes), pnpm can import your old lockfile and generate a pnpm-lock.yaml file that matches it.
If migrating from npm:
pnpm import package-lock.json
If migrating from yarn:
pnpm import yarn.lock
If you skip this step, running pnpm install in the next step will simply generate a fresh pnpm-lock.yaml based on the semver ranges in your package.json.
5. Install Dependencies
Now, run the installation using pnpm.
pnpm install
This will download your dependencies, create the hard links/symlinks, and build your new node_modules folder the pnpm way.
6. Prevent Accidental npm/yarn Usage
If you are working on a team, it’s easy for another developer to accidentally run npm install and create a confusing mix of lockfiles.
To prevent this, add a preinstall script to your package.json:
"scripts": {
"preinstall": "npx only-allow pnpm",
// ... your other scripts
}
This script runs automatically before any installation command. If someone tries to run npm install or yarn install, it will throw an error and remind them to use pnpm.