Skip to main content
This covers dependency-related problems that occur in pnpm workspace environments and how to resolve them.

Strict Dependency Resolution

Symptoms

pnpm install

 ERR_PNPM_PEER_DEP_ISSUES  Unmet peer dependencies

.
└─┬ @types/react 19.2.7
  └── βœ• missing peer prop-types@^15.0.0

Peer dependencies that should be installed:
  prop-types@^15.8.1

Cause

pnpm has stricter dependency resolution than Yarn or npm. It doesn’t automatically install missing peer dependencies and requires explicit installation.

Solutions

1. Explicitly Install Peer Dependency

pnpm add -D prop-types
.npmrc:
auto-install-peers=true
Drawback: Dependency tree can become unpredictable

3. Use pnpm.overrides

package.json:
{
  "pnpm": {
    "overrides": {
      "prop-types": "^15.8.1"
    }
  }
}

Workspace Protocol Error

Symptoms

 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND

In sonamu: "workspace:*" is in the dependencies but no package
named "sonamu" is present in the workspace

Cause

Used workspace:* protocol but that package doesn’t exist in the workspace.

Solutions

1. Check Workspace Packages

pnpm-workspace.yaml:
packages:
  - examples/**/*
  - modules/**/*
  - "!modules/create-sonamu/template/**/*"

2. Check Package Name

# Check all packages in workspace
pnpm ls -r --depth -1

3. Fix package.json

{
  "dependencies": {
    "sonamu": "workspace:*"  // sonamu package must exist in workspace
  }
}

Catalog Version Mismatch

Symptoms

 ERR_PNPM_CATALOG_VERSION_MISMATCH

Package "react" has version "19.2.3" in catalog but "18.3.0"
in package.json

Cause

Version defined in pnpm-workspace.yaml catalog differs from package.json version.

Solutions

package.json:
{
  "dependencies": {
    "react": "catalog:"  // Use version from pnpm-workspace.yaml
  }
}

2. Update Catalog

pnpm-workspace.yaml:
catalog:
  react: ^19.2.3  # Update to match package.json

3. Unify All Workspace to Catalog Version

# Update all packages' dependencies to catalog version
pnpm update -r

Hoisting Issues

Symptoms

Error: Cannot find module '@types/node'
Require stack:
- /path/to/your/project/src/index.ts
Module is installed but cannot be found.

Cause

pnpm doesn’t hoist dependencies by default. Each package is isolated under node_modules/.pnpm.

Solutions

1. Use public-hoist-pattern

.npmrc:
public-hoist-pattern[]=@types/*
public-hoist-pattern[]=eslint-*
Hoists specific packages to root node_modules.

2. shamefully-hoist (Last Resort)

.npmrc:
shamefully-hoist=true
Warning: Works like npm/yarn but gives up pnpm’s advantages.

3. Declare Correct Dependencies

{
  "devDependencies": {
    "@types/node": "catalog:"
  }
}
Declaring required packages directly is safest.

TypeScript Path Mapping Error

Symptoms

import { UserModel } from "@/application/user/user.model";
// Error: Cannot find module '@/application/user/user.model'

Cause

TypeScript path mapping doesn’t work properly due to pnpm’s strict dependency resolution.

Solutions

1. tsconfig.json Configuration

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

2. tsx/ts-node Configuration

tsconfig.json:
{
  "ts-node": {
    "require": ["tsconfig-paths/register"]
  }
}
Install:
pnpm add -D tsconfig-paths

Phantom Dependencies

Symptoms

A package imported directly in code doesn’t exist in package.json but works.
import _ from "lodash-es";  // Not in package.json
Works locally but fails in CI or other environments.

Cause

Phantom Dependencies - accidentally accessible through dependencies of other packages.

Solutions

1. Add Explicit Dependency

pnpm add lodash-es

2. Run pnpm check

# Check phantom dependencies
pnpm ls --depth=Infinity

# Check why a package exists
pnpm why <package-name>

onlyBuiltDependencies Error

Symptoms

 ERR_PNPM_CANNOT_RESOLVE_OPTIONAL_DEPENDENCY

Could not resolve optional dependency @parcel/watcher

Cause

Packages in onlyBuiltDependencies list are configured to install optionally only.

Solution

pnpm-workspace.yaml:
onlyBuiltDependencies:
  - "@parcel/watcher"
  - "@swc/core"
  - bcrypt
  - esbuild
  - sharp
These packages contain binaries and require platform-specific installation. If installation fails:
# Retry installation
pnpm install --force

# Or specific package only
pnpm add sharp --force

Overrides Not Applied

Symptoms

pnpm.overrides is configured but not applied.
{
  "pnpm": {
    "overrides": {
      "axios": ">=1.0.0"
    }
  }
}

Causes

  1. Overrides syntax is wrong
  2. Set in non-workspace-root location
  3. pnpm version is old

Solutions

1. Correct Overrides Syntax

package.json (workspace root):
{
  "pnpm": {
    "overrides": {
      "axios@<1.0.0": ">=1.0.0",
      "lodash": "^4.17.21"
    }
  }
}

2. Use in pnpm-workspace.yaml

overrides:
  axios@<0.30.0: ">=0.30.0"
  axios@>=0.8.1 <0.28.0: ">=0.28.0"

3. Verify Applied

# Regenerate lockfile
pnpm install --force

# Check version
pnpm why axios

Circular Workspace Dependencies

Symptoms

 ERR_PNPM_WORKSPACE_CYCLE

There is a circular dependency in the workspace:
  @sonamu-kit/react-sui -> @sonamu-kit/ui -> @sonamu-kit/react-sui

Cause

Workspace packages reference each other, causing circular dependency.

Solutions

1. Redesign Dependency Structure

// @sonamu-kit/react-sui/package.json
{
  "dependencies": {
    "@sonamu-kit/ui": "workspace:*"  // ❌ react-sui depends on ui
  }
}

// @sonamu-kit/ui/package.json
{
  "dependencies": {
    "@sonamu-kit/react-sui": "workspace:*"  // ❌ ui depends on react-sui
  }
}
Solution:
// Extract common dependencies into separate package
// Create @sonamu-kit/common, both reference it

2. Use peerDependencies

{
  "peerDependencies": {
    "@sonamu-kit/ui": "workspace:*"
  }
}

Cache Issues

Symptoms

Previous version is still used even after updating dependencies.

Solutions

1. Clean pnpm store

# Verify store
pnpm store prune

# Full cleanup
pnpm store prune --force

2. Complete Reinstall

# Delete node_modules
rm -rf node_modules

# Reinstall keeping lockfile
pnpm install --frozen-lockfile

# Or fresh install
rm pnpm-lock.yaml
pnpm install