fix-peer-deps v1.1.12
fix-peer-deps
A modern CLI tool to analyze and fix peer dependency issues across multiple package managers (npm, yarn, pnpm, bun).
Description
fix-peer-deps
is a powerful command-line tool designed to simplify the often complex task of managing peer dependencies in JavaScript/Node.js projects. It addresses common challenges developers face when working with packages that have peer dependency requirements:
- ๐ Intelligent Detection: Automatically identifies peer dependency conflicts and missing requirements
- ๐ฏ Smart Resolution: Suggests the most compatible versions based on your project's constraints
- ๐ Universal Compatibility: Works across major package managers (npm, yarn, pnpm, bun)
- ๐ก Developer-Friendly: Provides clear, actionable suggestions with copy-paste ready commands
- ๐จ Modern Interface: Features a beautiful CLI interface with progress tracking and visual feedback
Why Use fix-peer-deps?
- Save Time: Quickly identify and resolve peer dependency issues that could take hours to debug manually
- Prevent Errors: Catch peer dependency conflicts before they cause runtime issues
- Cross-Platform: Works with any package manager, making it versatile for different project setups
- Clear Guidance: Get straightforward solutions instead of cryptic error messages
- Modern Experience: Enjoy a beautiful, interactive terminal interface while fixing dependencies
How It Works
The tool performs a deep analysis of your project's dependency tree by:
- Scanning your project's package manager and lock files
- Analyzing direct and transitive dependencies
- Identifying peer dependency conflicts and missing requirements
- Generating specific, actionable solutions
- Providing clear commands to resolve each issue
Features
- ๐ฏ Accurately detects and categorizes peer dependency issues
- ๐ฆ Distinguishes between critical and optional peer dependencies
- ๐ Supports modern package managers (npm, yarn 4.x, pnpm, bun)
- ๐จ Beautiful CLI interface with progress indicators
- ๐งช Intelligent filtering of development-only dependencies
- โก Automatic fix mode with
--fix
option
Try it Online
You can try fix-peer-deps directly in your browser using RunKit:
// Interactive demo of fix-peer-deps features
const { analyzePeerDependencies, detectPackageManager, autoFix, checkDeepPeerDependencies } = require('fix-peer-deps');
// Sample project with various dependency scenarios
const project = {
dependencies: {
"react": "17.0.2",
"react-dom": "18.2.0",
"@mui/material": "5.15.5",
"@mui/lab": "5.0.0-alpha.161"
}
};
// Sample dependency info for deep checking
const depInfo = {
"@mui/lab": {
version: "5.0.0-alpha.161",
peerDependencies: {
"@mui/material": "^5.0.0",
"react": "^17.0.0 || ^18.0.0"
}
}
};
// Demonstrate key features
async function demonstrateFeatures() {
try {
// 1. Detect Package Manager
const packageManager = await detectPackageManager();
console.log('๐ฆ Package Manager:', packageManager);
// 2. Analyze Dependencies
const issues = await analyzePeerDependencies();
console.log('\n๐ Analysis Results:');
console.log('โข Critical Issues:', issues.critical.length);
console.log('โข Optional Issues:', issues.optional.length);
// 3. Check Deep Dependencies
const visited = new Set();
const deepIssues = await checkDeepPeerDependencies(
'@mui/lab',
depInfo['@mui/lab'],
depInfo,
visited
);
console.log('\n๐ณ Deep Dependencies:');
deepIssues.forEach(issue =>
console.log(`โข ${issue.package} โ ${issue.dependency}`)
);
// 4. Get Auto-Fix Commands
const fixCommands = await autoFix();
console.log('\n๐ ๏ธ Suggested Fixes:');
fixCommands.forEach(cmd => console.log('โข', cmd));
} catch (error) {
console.error('โ Error:', error.message);
}
}
demonstrateFeatures();
The example above demonstrates:
- Package manager detection (npm, yarn, pnpm, bun)
- Dependency analysis with version conflict detection
- Deep peer dependency checking
- Missing peer dependency identification
- Optional dependency suggestions
- Auto-fix command generation
- Error handling and formatted output
Try it yourself by clicking the RunKit badge above!
Installation
Method 1: Run Directly (Recommended for one-time use)
# Using npm
npx fix-peer-deps
# Using yarn
yarn dlx fix-peer-deps
# Using pnpm
pnpm dlx fix-peer-deps
# Using bun
bunx fix-peer-deps
Method 2: Global Installation
If you frequently work with multiple Node.js projects, you can install the package globally:
# Using npm
npm install -g fix-peer-deps
# Using yarn
yarn global add fix-peer-deps
# Using pnpm
pnpm add -g fix-peer-deps
# Using bun
bun add -g fix-peer-deps
After global installation:
Verify the installation:
fix-peer-deps --version
You can now run the tool from any directory:
cd /path/to/your/project fix-peer-deps
Usage
Basic Usage
Navigate to your project directory:
cd /path/to/your/project
Run the analysis:
fix-peer-deps
Review the output:
- Critical issues that need attention
- Optional dependencies that might improve development
- Suggested commands to fix issues
Fix issues either:
- Manually using the suggested commands, or
- Automatically using the
--fix
option
Command Options
# Analyze and get suggestions
fix-peer-deps
# Automatically fix issues
fix-peer-deps --fix
# Show help information
fix-peer-deps --help
# Check version
fix-peer-deps -v
# or
fix-peer-deps --version
Available Commands
fix-peer-deps
: Analyzes your project and provides suggestionsfix-peer-deps --fix
: Automatically installs missing peer dependenciesfix-peer-deps -h, --help
: Shows help informationfix-peer-deps -v, --version
: Shows the current version
The tool will:
- Detect your package manager
- Analyze your dependencies
- Categorize issues by severity
- Provide specific commands to fix critical issues
- List optional dependencies that might improve your development experience
Understanding the Output
The tool categorizes peer dependency issues into two types:
Critical Issues (๐จ)
- Missing or incompatible dependencies that are required for packages to function
- These should typically be resolved to ensure proper functionality
- Can be automatically fixed using the
--fix
option
Optional Issues (โ ๏ธ)
- Development dependencies that might enhance your development experience
- Type definitions (@types/*)
- Optional peer dependencies
- Development tool integrations
Example Output
When you run fix-peer-deps
, you'll see output similar to this:
๐ Detecting package manager... npm
๐ฆ Analyzing dependencies...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 100%
๐ Found Issues:
โข 2 critical issues
โข 1 optional issue
๐จ Critical Issues:
react-dom requires react@^18.2.0
Current: 17.0.2
@mui/material requires react@^17.0.0 || ^18.0.0
Current: missing
โ ๏ธ Optional Issues:
@types/react optionally requires react@*
Current: 17.0.2
๐ Suggested Actions:
Run the following commands to resolve critical issues:
npm install react@18.2.0
npm install @mui/material
๐ก Tips:
โข Use --fix to automatically resolve critical issues
โข Optional issues can be resolved manually if needed
This output shows:
- Package manager detection
- Progress of dependency analysis
- Summary of found issues
- Detailed breakdown of critical and optional issues
- Specific commands to resolve problems
- Helpful tips for using the tool
Common Use Cases
Starting a New Project:
cd my-new-project npm init -y npm install some-package fix-peer-deps # Check for any peer dependencies
Fixing Dependency Issues:
fix-peer-deps --fix # Automatically install missing dependencies
Auditing Dependencies:
fix-peer-deps # Review all peer dependency relationships
CI/CD Integration:
# In your CI script fix-peer-deps || exit 1 # Exit with error if critical issues found
Configuration
The tool automatically detects your package manager based on:
- The
packageManager
field in package.json - Lock files present in your project
- Defaults to npm if no specific manager is detected
Supported Package Managers
- npm (all versions)
- yarn (including yarn 4.x)
- pnpm
- bun
Troubleshooting
Common Issues
Command Not Found
# Reinstall globally npm install -g fix-peer-deps
Permission Errors
# Use sudo for global installation if needed sudo npm install -g fix-peer-deps
Package Manager Detection Issues
# Ensure you're in a directory with package.json ls package.json
Error Messages
- "No package.json found": Navigate to your project root directory
- "Failed to fix dependencies": Check your network connection and try again
- "Analysis failed": Ensure your package manager is properly installed
Future Scope
AI Integration
- ๐ค Local AI-powered dependency analysis using Ollama
- ๐ Smart version recommendations based on project context
- ๐ Intelligent compatibility checking
- ๐ก๏ธ Automated security considerations
- ๐ก Personalized upgrade path suggestions
These enhancements will help:
- Automate decision-making for version conflicts
- Predict potential compatibility issues
- Provide context-aware security recommendations
- Optimize dependency trees automatically
Requirements
- Node.js 14.x or higher
- One of the supported package managers installed
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT ยฉ Sudeepta Sarkar
Author
Sudeepta Sarkar sudsarkar13@gmail.com
Issues
If you encounter any problems or have suggestions for improvements, please file an issue at: https://github.com/sudsarkar13/packages/issues
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago