React 19 introduced features like Server Components, Turbopack, and Concurrent Rendering. They improve performance, but they’ve also caused peer dependency conflicts across the ecosystem. If you can’t live without these features, this guide covers resolving the conflicts without --force, --legacy-peer-deps, or downgrading to React 18.
I first ran into this with Radix UI and ShadCN, which they addressed, but after some experimenting I found similar issues in libraries like @testing-library/react, react-scripts, eslint-plugin-react, react-redux, recharts, cmdk, and at one point react-dom. Many of these will likely receive updates (like React DOM), so run your own experiments.
The quickest fix is to use Yarn or Vite, both of which are great. I’ll cover the other options below.
Understanding peer dependency conflicts
Peer dependencies declare which versions of a package (e.g., React) a library is compatible with. Conflicts typically arise when:
Outdated libraries: Libraries declare compatibility only up to React 18.
Strict version constraints: Exact versions are required, disallowing React 19.
Multiple React versions: Different packages install conflicting versions of React.
Stricter package manager enforcement: npm 7+ enforces peer dependency rules more strictly.
These conflicts cause installation errors or runtime issues like: Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
Example scenarios
A known issue with create-react-app (CRA) occurs when using React 19. The default installation installs React 19, while some dependencies, like @testing-library/react, specify a peer dependency of react@"^18.0.0". This leads to errors like npm ERR! peer react@"^18.0.0" from @testing-library/react@13.4.0.
Attempts to resolve this with --legacy-peer-deps or by specifying a script version like npx create-react-app myprog --scripts-version react-scripts@5.0.1 still result in conflicts.
If you’re cool with React 18, install it in your project before running create-react-app.
npm install react@18 react-dom@18
npx create-react-app myprogHow to identify dependency conflicts
1. Run npm ls to view the dependency tree
The npm ls command shows your project’s dependency tree and helps identify conflicting packages. It displays the versions of React used by different packages and highlights conflicts with UNMET PEER DEPENDENCY errors.
2. Use npm install to check for conflicts
Running npm install or npm update will often reveal peer dependency conflicts. If there are any, npm displays warnings like: npm WARN some-package@1.0.0 requires a peer of react@¹⁸ but none is installed.
3. Inspect conflicts using npm outdated
The npm outdated command shows outdated dependencies and helps you spot potential conflicts with newer versions. Focus on packages related to React, as they’re the likely source.
4. Audit dependencies with npm ls --depth=0
npm ls --depth=0 lists the top-level dependencies (those installed directly in your project), which helps you narrow down the packages to inspect for peer dependency issues.
5. Check dependency versions in package.json
If the conflicting versions aren’t obvious, use cat package.json to inspect your package.json file. Then compare the specified versions of React, React DOM, and other critical libraries with the peer dependencies the conflicting packages require.
6. Use npm dedupe to detect duplicates
Conflicts sometimes come from duplicate React installations. Run npm dedupe to deduplicate your node_modules, then re-run npm ls react to check whether multiple React versions are installed.
7. Use yarn why
For Yarn users, yarn why explains why a package is installed and which dependencies require it.
Resolving peer dependency conflicts
Once you’ve identified the conflicts, any of these strategies can help.
1. Manually roll back the version in your project
Install compatible versions of the conflicting packages using npm install @. This could cause issues if the package relies on features found in React 19.
2. Use overrides (npm) or resolutions (yarn)
Force compatible versions in package.json without altering global settings, then run npm install.
// NPM overrides
{
"overrides": {
"react": "19.x",
"react-dom": "19.x"
}
}
// Yarn resolutions
{
"resolutions": {
"react": "19.x",
"react-dom": "19.x"
}
}3. Request updates from maintainers
Search the package’s repository for similar issues, write a ticket, and ask the maintainers for React 19 support. While waiting, apply other fixes temporarily.
4. Fork and patch outdated libraries
If a critical library hasn’t updated its peerDependencies:
Fork the library on GitHub. Fork the repository to your own GitHub account so you have full control over the code and can modify it without affecting the original project.
Update the package to support React 19. Open the package.json file in the forked repository and modify the peerDependencies section to include React 19.
Test and verify compatibility. Run the library’s test suite and make sure the tests pass. The Readme or package.json scripts section should say how.
Publish your fork. Publish the updated package to your npm account under a scoped name, e.g.,
@your-username/Be a good steward of the code and the ecosystem. Submit a well-documented pull request (PR) to the original repository. Explain the changes with “why”, “how” and “what”, and follow their contribution guidelines (generally in
/CONTRIBUTORS.md).
5. Switch to compatible alternatives
If an outdated package shows no sign of updating, replace it with a modern, actively maintained alternative. In my case, I would use libraries like MUI or Chakra UI instead of ShadCN.
6. Isolate packages in a monorepo
Use tools like Nx or Turborepo to structure your project as a monorepo, isolating conflicting packages in separate workspaces to minimize conflicts.
7. Write a custom dependency resolution script
If you need to automate installation, deployment, or modifying node_modules after installation to resolve peer dependency conflicts:
Install the conflicting packages.
Write a script to update peerDependencies in their package.json files.
Rebuild the project.
The script might look something like this:
// This script modifies the peerDependencies of conflicting packages directly within node_modules.
// Use Node.js to automate this process by adding "node resolve-peer-deps.js" to your package.json config
const fs = require('fs');
const path = require('path');
const packagesToUpdate = [
{
name: '@testing-library/react',
newPeerDependencies: {
react: '>=18.0.0 <20.0.0',
'react-dom': '>=18.0.0 <20.0.0',
},
},
{
name: 'another-library',
newPeerDependencies: {
react: '>=18.0.0 <20.0.0',
},
},
];
const resolvePath = (pkgName) => path.resolve('node_modules', pkgName, 'package.json');
const readJson = (filePath) => JSON.parse(fs.readFileSync(filePath, 'utf8'));
const writeJson = (filePath, data) => fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
const updatePeerDeps = ({ name, newPeerDependencies }) => {
try {
const packageJsonPath = resolvePath(name);
if (!fs.existsSync(packageJsonPath)) throw new Error(`Package not found: ${name}`);
const packageJson = readJson(packageJsonPath);
packageJson.peerDependencies = { ...packageJson.peerDependencies, ...newPeerDependencies };
writeJson(packageJsonPath, packageJson);
console.log(`[Updated] ${name} peerDependencies`);
} catch (error) {
console.error(`[Error] ${name}: ${error.message}`);
}
};
packagesToUpdate.forEach(updatePeerDeps);8. Monitor updates with Renovate or Dependabot
Automate dependency updates with tools like Renovate, Dependabot, or my go-to npm-check-updates (ncu).
9. Just use --legacy-peer-deps and hang tight
Dealing with peer dependency conflicts is never fun, but it isn’t a show stopper. Not every project needs the same fix, so try a few of these approaches, see what sticks, and save any trick you discover in your gist or snippits.
Good luck!