Skip to content
SunnyWriteUps
Go back

Getting Started with pnpm in Angular A 2026 Guide

Edit page

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:

  1. Generates the standard Angular boilerplate.
  2. Uses pnpm install instead of npm install under the hood.
  3. Generates a pnpm-lock.yaml file instead of package-lock.json.
  4. Automatically updates your angular.json file so that future CLI commands (like adding libraries) know to use pnpm.

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

Performance & Coding Standards

State Management

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:

Note: You can delete these manually, or use a tool like npkill to quickly remove node_modules.

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.


Edit page
Share this post on:

Previous Post
AI-Assisted Architecture in Frontend Compilers Analyzing the Gemini-Powered Angular "Lite" Prototype
Next Post
Unlocking the `package.json` A Guide to Our Angular Architecture