Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems installing react bacause of dependencies with babel

Basically this. I've tried with both

npm init react-app my-app

and

npx create-react-app my-app

and I get always this message:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: @babel/[email protected]
npm ERR! node_modules/@babel/core
npm ERR!   @babel/core@"7.12.3" from [email protected]
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"*" from the root project
npm ERR!   @babel/core@"^7.12.3" from @svgr/[email protected]
npm ERR!   node_modules/@svgr/webpack
npm ERR!     @svgr/webpack@"5.5.0" from [email protected]
npm ERR!     node_modules/react-scripts
npm ERR!       react-scripts@"*" from the root project
npm ERR!   9 more (babel-jest, babel-loader, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @babel/core@"^7.13.0" from @babel/[email protected]
npm ERR! node_modules/@babel/preset-env/node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining
npm ERR!   @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@"^7.13.12" from @babel/[email protected]
npm ERR!   node_modules/@babel/preset-env
npm ERR!     @babel/preset-env@"^7.12.1" from @svgr/[email protected]
npm ERR!     node_modules/@svgr/webpack
npm ERR!       @svgr/webpack@"5.5.0" from [email protected]
npm ERR!       node_modules/react-scripts
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\Zio Matteo\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\Zio Matteo\AppData\Local\npm-cache\_logs\2021-06-08T08_46_00_758Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json
Deleting first/ from C:\Users\Zio Matteo\Desktop\react
Done.
npm ERR! code 1
npm ERR! path C:\Users\Zio Matteo\Desktop\react
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c create-react-app "first"

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Zio Matteo\AppData\Local\npm-cache\_logs\2021-06-08T08_46_01_359Z-debug.log

I've also updated node but nothing works. My package.json is empty because this is the first package I'm trying to install, so I don't have node_modules folder neither. What can I do?

like image 790
matteo Avatar asked Jun 08 '21 08:06

matteo


People also ask

How do I remove Babel jest from dependencies?

Remove "babel-jest" from dependencies and/or devDependencies in the package. json file in your project folder. 4. Run npm install or yarn, depending on the package manager you use.In most cases, this should be enough to fix the problem.

Can I use react without Babel?

It executes React code and understands JSX and modern JavaScript features. It does that without using Babel.

Do I need to install Babel for react?

Essentially, using this command, you need not worry about installing Babel as everything is taken care of under the hood. In the event you are not creating your project with create-react-app, Babel can be installed in your React project with the following commands.

Why is Babel-loader not installed in create-react-app?

The Problem create-react-appinitializes a repository where babel-loader is installed as an older version than needed. LOG: There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.

What are the dependencies of the react-scripts package?

The react-scripts package provided by Create React App requires a dependency: "babel-loader": "8.0.4" Don't try to install it manually: your package manager does it automatically.

What if a different version of Babel-loader is installed?

However, a different version of babel-loader was detected higher up in the tree: D:\Reactjs ode_modules\babel-loader (version: 8.0.6) Manually installing incompatible versions is known to cause hard-to-debug issues . If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .e nv file in your project.


1 Answers

This is an issue of npm version. Upgrade to the latest version of npm:

npm install -g npm@latest

Also add babel:

npm install --save-dev @babel/core

If this solution doesn't work, you can simply try older npm version:

npm install [email protected] -g
like image 66
Ahmad MOUSSA Avatar answered Oct 12 '22 23:10

Ahmad MOUSSA