contentlayerdev / contentlayer

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://www.contentlayer.dev
MIT License
3.27k stars 200 forks source link

A peer dependency conflict between next.js & next-contentlayer #663

Closed aimahusnain closed 1 day ago

aimahusnain commented 2 months ago

I created a Next.js app and applied Contentlayer to build an MDX blog. Locally, I use --force to install packages, but when deploying to Vercel, it results in an error:

[17:01:17.116] Installing dependencies... [17:01:24.839] npm ERR! code ERESOLVE [17:01:24.842] npm ERR! ERESOLVE could not resolve [17:01:24.843] npm ERR! [17:01:24.844] npm ERR! While resolving: next-contentlayer@0.3.4 [17:01:24.844] npm ERR! Found: next@14.2.3 [17:01:24.845] npm ERR! node_modules/next [17:01:24.845] npm ERR! next@"14.2.3" from the root project [17:01:24.846] npm ERR! peer next@"*" from next-sitemap@4.2.3 [17:01:24.854] npm ERR! node_modules/next-sitemap [17:01:24.855] npm ERR! next-sitemap@"^4.2.2" from the root project [17:01:24.855] npm ERR! 1 more (next-themes) [17:01:24.857] npm ERR! [17:01:24.857] npm ERR! Could not resolve dependency: [17:01:24.858] npm ERR! peer next@"^12 || ^13" from next-contentlayer@0.3.4 [17:01:24.858] npm ERR! node_modules/next-contentlayer [17:01:24.858] npm ERR! next-contentlayer@"^0.3.4" from the root project [17:01:24.859] npm ERR! [17:01:24.859] npm ERR! Conflicting peer dependency: next@13.5.6 [17:01:24.860] npm ERR! node_modules/next [17:01:24.866] npm ERR! peer next@"^12 || ^13" from next-contentlayer@0.3.4 [17:01:24.866] npm ERR! node_modules/next-contentlayer [17:01:24.866] npm ERR! next-contentlayer@"^0.3.4" from the root project [17:01:24.866] npm ERR! [17:01:24.866] npm ERR! Fix the upstream dependency conflict, or retry [17:01:24.867] npm ERR! this command with --force or --legacy-peer-deps [17:01:24.872] npm ERR! to accept an incorrect (and potentially broken) dependency resolution. [17:01:24.872] npm ERR! [17:01:24.873] npm ERR! [17:01:24.873] npm ERR! For a full report see: [17:01:24.873] npm ERR! /vercel/.npm/_logs/2024-06-21T12_01_17_808Z-eresolve-report.txt [17:01:24.873] [17:01:24.873] npm ERR! A complete log of this run can be found in: /vercel/.npm/_logs/2024-06-21T12_01_17_808Z-debug-0.log [17:01:24.910] Error: Command "npm install" exited with 1

I asked ChatGPT for a solution to this error, and it suggested downgrading the version of Next.js, but I don't want to do that. The second option was to use --force, but how can I apply that on Vercel?

Koala0CE commented 2 months ago

I used --force and it's installed now but not working properly for me

aimahusnain commented 2 months ago

I downgrade the next.js so it's running for now, but when I got the solution so, I will upgrade the next.js version

ghost commented 2 months ago

Add this to your package.json to override the peer dependency version, then please upgrade your next.js version to keep it safe against vulnerabilities:

"overrides": {

    "next-contentlayer": {
        "next": "$next"
    }

}
stale[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.