0

I'm trying to build a gatsby project. My project didn't had any package conflict until I installed google analytics plugin.

I am getting dependency error even after deleting node_modules, package-lock.json, .cache.

The log:

pegasus@pegasus:~/Documents/Final_Website/blog$ npm install gatsby-plugin-mdx gatsby-source-filesystem @mdx-js/react
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: blog@1.0.0
npm ERR! Found: gatsby@4.25.6
npm ERR! node_modules/gatsby
npm ERR!   gatsby@"^4.10.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer gatsby@"^5.0.0-next" from gatsby-plugin-google-analytics@5.9.0
npm ERR! node_modules/gatsby-plugin-google-analytics
npm ERR!   gatsby-plugin-google-analytics@"^5.9.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /home/pegasus/.npm/_logs/2023-05-04T05_04_02_747Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pegasus/.npm/_logs/2023-05-04T05_04_02_747Z-debug-0.log

How to resolve it?

NobinPegasus
  • 545
  • 2
  • 16
  • please describe the environment, what are the node and npm and what is your OS? maybe it is also helpful to add your package.json here – sina.ce May 04 '23 at 09:33
  • solved it. By deleting gatsby-plugin-google-analytics@5.9.0 entry from package.json But my question is in future if I wanna add gatsby-plugin-google-analytics@5.9.0 to my project. How can I do it without breaking it and making the dependency conflicts. – NobinPegasus May 04 '23 at 13:35

1 Answers1

0

The error message says that gatsby-plugin-google-analytics requires gatsby@5 but your project is using/requiring gatsby@4. Your options are:

  1. Update your project to Gatsby 5.
  2. Install an earlier version of the analytics plugin that is compatible with Gatsby 4.
  3. Take your chances with npm install --legacy-peer-deps which will probably install everything just fine but you might end up running into bugs/incompatibilities.
  4. Uninstall the analytics plugin.
Trott
  • 66,479
  • 23
  • 173
  • 212