Home > Back-end >  Unable to install Stripe npm package
Unable to install Stripe npm package

Time:04-01

I am trying to install Stripe NPM Package into react project using npm but unable to install it. Here is the error showing into the terminal.

PS C:\Users\adity\OneDrive\Desktop\stripe-payments> npm i @stripe/react-stripe-js
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from @stripe/[email protected]
npm ERR! node_modules/@stripe/react-stripe-js
npm ERR!   @stripe/react-stripe-js@"*" 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! See C:\Users\adity\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\adity\AppData\Local\npm-cache\_logs\2022-03-31T12_21_47_015Z-debug-0.log

CodePudding user response:

try running either npm install @stripe/react-stripe-js --force or npm install @stripe/react-stripe-js --legacy-peer-deps

if that doesnt work, then remove the node modules folder and reinastall all dependencies with the above commands

if it still doesnt work, you'll have to downgrade your react version from 18 to either 17 or 16

CodePudding user response:

You can try to use --force as you install it because it seems like it wants React v17 or v16, but the React you currently have is v18. I won't recommend using --force since it may cause somethings to break in the future from dependency errors, however as far as I was able to test, it works well:

npm install @stripe/react-stripe-js @stripe/stripe-js --force

Alternatively, you can change the version of your React app to v17 since v18 is pretty new and most components out there on npm would probably use v16 and v17. You can do this by going to your package.json and changing the version manually there. (For some reason there is not way to install react manually using create-react-app.) It's explained in this post here.

If you're using webpack (or you installed it without npx create-react-app, you can always just install react using:

npm i react@<your version here> react-dom@<your version here>

It should be able to work well without any dependency errors.

  • Related