Skip to main content
Configure npm-compatible settings using .npmrc files.

What is .npmrc?

.npmrc is a configuration file for npm-compatible package managers. Bun reads and respects most .npmrc settings for compatibility with existing projects.

File locations

Bun reads .npmrc files in this order (later files override earlier ones):
  1. Built-in defaults
  2. Global config - /etc/npmrc (Linux/macOS)
  3. User config - ~/.npmrc
  4. Project config - ./npmrc (in project root)

Per-project

Per-user

Global

Syntax

Comments

Key-value pairs

Scoped settings

Auth tokens

Common settings

Registry

Set default registry:

Scoped registries

Authentication

Token auth:
Basic auth:

SSL/TLS

Strict SSL:
Custom CA certificate:

Proxy

HTTP proxy:
No proxy for specific hosts:

Package settings

Save prefix:
Save exact:

Supported settings

Bun supports these .npmrc settings:

Registry settings

Authentication

SSL/TLS

Proxy

Lockfile

Install options

Environment variables

Reference environment variables:
Set variables:

Examples

GitHub Packages

Usage:

GitLab Packages

Private registry with basic auth

Encode password:

Corporate proxy

Multiple registries

Security

Don’t commit tokens

Use environment variables:
Add to .gitignore:

Per-project tokens

For projects requiring auth:

CI/CD

Generate .npmrc in CI:

Troubleshooting

Check which .npmrc is used

Bun reads in this order:
  1. /etc/npmrc
  2. ~/.npmrc
  3. ./npmrc
Later files override earlier ones.

Debug registry configuration

Clear auth cache

Delete cached credentials:
Or remove specific tokens:

Test .npmrc settings

Create test .npmrc:
Install:

Permission errors

Fix .npmrc permissions:

Migration

From npm

Existing .npmrc works with Bun:

From Yarn

Yarn’s .yarnrc is different. Convert to .npmrc:
To:

From pnpm

pnpm uses .npmrc - should work with Bun directly.

bunfig.toml vs .npmrc

Bun supports both:

.npmrc (npm-compatible)

bunfig.toml (Bun-specific)

Precedence

bunfig.toml overrides .npmrc.

When to use each

Use .npmrc for:
  • Cross-tool compatibility (npm, Yarn, pnpm)
  • Auth tokens
  • Registry configuration
Use bunfig.toml for:
  • Bun-specific settings
  • Advanced configuration
  • Better IDE support (TOML)

Best practices

Separate auth from config

Merge in CI:

Document required setup

//registry.company.com/:_authToken=YOUR_TOKEN

Use environment variables

Validate .npmrc

Check syntax:

Keep it minimal