This document outlines the plan to migrate the current npm-based build system to Bun. This change will replace the package manager while maintaining all existing dependencies and project functionality. Bun is designed to be a faster, more efficient alternative to npm that maintains compatibility with existing Node.js projects.
- Package Manager: npm (as evidenced by
package-lock.json) - Scripts in package.json:
dev:next devbuild:next buildstart:next startlint:eslint .prepare:husky install
- Dependencies: Standard Next.js project dependencies with contentlayer, React, TypeScript, Tailwind CSS, and various dev dependencies
- Husky Integration: Uses npm scripts in
.husky/pre-commithook (npm run lint)
This migration is relatively straightforward because:
- Bun maintains compatibility with existing npm workflows and package.json
- No code changes are required in the project
- Bun can read npm's configuration and automatically convert lockfiles
- The project is a standard Next.js application without complex npm-specific configurations
Changes Required:
- Install Bun on the development and production systems
- No changes needed to package.json dependencies
Changes Required:
- Replace
npm installwithbun install - Replace
npm run <script>withbun <script> - Replace
npm exec <bin>withbun <bin> - Replace
npx <package>withbunx <package>
Command Mapping:
npm install→bun installorbun inpm run dev→bun devnpm run build→bun buildnpm run start→bun startnpm run lint→bun lint
Changes Required:
- Update
.husky/pre-committo use Bun instead of npm - Change
npm run linttobun lint
Changes Required:
- Bun will automatically convert
package-lock.jsontobun.lockb(Bun's binary lockfile) - The original
package-lock.jsoncan be removed after successful migration - Add
bun.lockbto version control
Changes Required:
- Update Dockerfile if it relies on npm commands
- Update any CI/CD pipelines that use npm commands
- Update any documentation referencing npm commands
- Install Bun on development machine(s)
- Verify Bun installation:
bun --version - Test Bun compatibility with current project:
bun install - Run development server:
bun dev - Run build:
bun build - Run linting:
bun lint
- Update
.husky/pre-committo use Bun:#!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" bun lint - Verify Husky hooks work with Bun
- Run
bun installto generatebun.lockb - Remove
package-lock.jsonfrom version control - Add
bun.lockbto version control - Test clean installation in a new directory
- Update Dockerfile to use Bun commands instead of npm
- Update any CI/CD pipeline scripts
- Test deployment with Bun
- Update documentation to reflect Bun usage
| npm | Bun |
|---|---|
npm install |
bun install or bun i |
npm install <package> |
bun add <package> |
npm install --save-dev <package> |
bun add --dev <package> or bun add -d <package> |
npm uninstall <package> |
bun remove <package> or bun rm <package> |
npm run <script> |
bun <script> |
npm exec <command> |
bun <command> |
npx <package> |
bunx <package> |
npm update <package> |
bun update <package> |
npm outdated |
bun outdated |
- Speed: Bun is significantly faster than npm for installing packages and running scripts
- Efficiency: Uses hardlinks to conserve disk space and installation times
- Compatibility: Maintains full compatibility with existing npm workflows
- Automatic conversion: Automatically converts npm lockfiles to Bun format
- All-in-one tool: Bun includes a package manager, runtime, bundler, and test runner
- Better performance: Simultaneous operations instead of sequential processing
- Some packages with pre-compiled binaries may need reinstallation
- Solution: Run
bun installto ensure all binaries are properly downloaded
- Husky may need to work with Bun instead of npm
- Solution: Tested during migration; update hook commands as needed
- Build servers may not have Bun installed
- Solution: Install Bun in CI environment or use Bun Docker images
- Team members need to install Bun
- Solution: Provide clear documentation and installation instructions
If issues arise during or after the migration:
- Restore
package-lock.jsonfrom version control backup - Reinstall using npm:
npm install - Revert
.husky/pre-committo usenpm run lint - Test functionality with original npm setup
-
bun installcompletes successfully -
bun devstarts development server -
bun buildcompletes successfully -
bun startruns production build -
bun lintexecutes without errors - Git hooks (Husky) work properly
- All dependencies are installed correctly
- Application functions as expected
- Deployment process works with Bun
Estimated Duration: 2-3 days
- Phase 1: 1 day (Environment setup and basic testing)
- Phase 2: Half day (Script and hook updates)
- Phase 3: Half day (Lockfile migration)
- Phase 4: 1 day (Deployment configuration and documentation)
- All npm commands successfully replaced with Bun equivalents
- Development workflow remains unchanged for developers
- Build process completes faster or at least as fast as before
- Deployment process continues to work without issues
- Git hooks continue to function properly
- No breaking changes to application functionality
- Improved performance in dependency installation and script execution