npm local development with workspace and link

January 26, 2026

The Problem

When developing multiple npm packages together (e.g., main app + shared lib), the normal publish workflow is slow:

  1. Fix bug in lib
  2. Publish lib to npm
  3. Update main's dependency version
  4. Test main

You want: change lib code → main sees it immediately.

Best when both packages live in the same repository.

Directory Structure

workspace/
  package.json        # Root package.json
  packages/
    lib-project/
      package.json
      src/...
    main-project/
      package.json
      src/...

Root package.json

{
  "private": true,
  "workspaces": ["packages/*"]
}

main-project/package.json

{
  "name": "@you/main-project",
  "dependencies": {
    "@you/lib-project": "workspace:*"
  }
}

workspace:* means: use local workspace version during development.

Setup

cd workspace
npm install

npm automatically symlinks lib-project into main-project/node_modules.

Now edit packages/lib-project → main-project sees changes instantly.

Publishing

When publishing, workspace:* gets replaced with actual version number automatically (npm 7+).

When packages are in different repositories.

cd /path/to/lib-project
npm link

This creates a global symlink to lib-project.

cd /path/to/main-project
npm link @you/lib-project

Now main-project/node_modules/@you/lib-project points to your local source.

cd /path/to/main-project
npm unlink @you/lib-project
npm install  # Restore from registry

⚠️ Warning: npm link can cause issues with peer dependencies and multiple React instances. Workspaces are more reliable.

Solution 3: file: Protocol (Quick & Dirty)

For temporary local testing:

{
  "dependencies": {
    "@you/lib-project": "file:../lib-project"
  }
}

⚠️ Warning: Never publish with file: dependencies. Others can't install your package.

Solution 4: Git URL (No npm Release)

For quick fixes before official release:

{
  "dependencies": {
    "@you/lib-project": "github:you/lib-project#fix-branch"
  }
}

Or pin to commit:

{
  "dependencies": {
    "@you/lib-project": "github:you/lib-project#a1b2c3d"
  }
}

Works for CI/team without publishing.

Keep Production Dependencies Clean

Your published package.json should use version dependencies:

{
  "dependencies": {
    "@you/lib-project": "^1.2.0"
  }
}

pnpm / yarn Equivalents

pnpm workspaces

pnpm-workspace.yaml:

packages:
  - 'packages/*'

Dependency:

"@you/lib-project": "workspace:*"

yarn workspaces

Same as npm workspaces syntax in package.json.

Linking

ToolLink Command
npmnpm link
pnpmpnpm link --global
yarnyarn link

Common Pitfalls

Pitfall 1: Changes not reflected

Cause: Symlink not created, or wrong version in node_modules.

Fix:

ls -la node_modules/@you/lib-project
# Should show symlink arrow (->)
# If not, re-run npm link or npm install (for workspaces)

Pitfall 2: Multiple React instances

Cause: Both main and lib have React in dependencies.

Fix: Move React to peerDependencies in lib:

{
  "peerDependencies": {
    "react": "^18.0.0"
  }
}

Pitfall 3: CI fails but local works

Cause: CI doesn't have your local symlinks.

Fix: CI must use published versions. For workspaces, npm handles this automatically when publishing.

Comparison

MethodUse CaseProsCons
WorkspacesMonorepoAutomatic, reliableRequires same repo
npm linkSeparate reposWorks anywhereCan break peer deps
file:Quick testSimpleCan't publish
git URLPre-release fixCI worksSlower, needs network

For most teams:

  1. Monorepo with workspaces - if packages are closely related
  2. Separate repos + npm link - for occasional cross-repo debugging
  3. Git URL - for sharing pre-release fixes with team/CI

© 2026 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2026-01-26). npm local development with workspace and link. https://caiborui.com/blog/2026-01-26-en-npm-local-development-workspace-link

@misc{borui2026-1a90e006,
  author = {borui},
  title = {{npm local development with workspace and link}},
  year = {2026},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2026-01-26-en-npm-local-development-workspace-link}
}