.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):
- Built-in defaults
- Global config -
/etc/npmrc(Linux/macOS) - User config -
~/.npmrc - 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:SSL/TLS
Strict SSL:Proxy
HTTP proxy:Package settings
Save prefix:Supported settings
Bun supports these.npmrc settings:
Registry settings
Authentication
SSL/TLS
Proxy
Lockfile
Install options
Environment variables
Reference environment variables:Examples
GitHub Packages
GitLab Packages
Private registry with basic auth
Corporate proxy
Multiple registries
Security
Don’t commit tokens
Use environment variables:.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:/etc/npmrc~/.npmrc./npmrc
Debug registry configuration
Clear auth cache
Delete cached credentials:Test .npmrc settings
Create test.npmrc:
Permission errors
Fix.npmrc permissions:
Migration
From npm
Existing.npmrc works with Bun:
From Yarn
Yarn’s.yarnrc is different. Convert to .npmrc:
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
- Bun-specific settings
- Advanced configuration
- Better IDE support (TOML)