4
respostas

erro no git?

oi gente, fui dar inicio no projeto mas tive diversos erros. Aparentemente o react é instalado e iniciado, porém, ele começa a dar erro ao inicializar o repositório do git. Já tentei diversas vezes corrigir isso, até apagar manualmente a pasta do projeto eu tentei, mas sempre obtive os erros.

Segue o erro: PS C:\Users\Davi\Desktop\Alura\fullstack-react-node> npx create-react-app .

Creating a new React app in C:\Users\Davi\Desktop\Alura\fullstack-react-node.

Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts with cra-template...

added 1320 packages in 2m

265 packages are looking for funding run npm fund for details

Initialized a git repository.

Installing template dependencies using npm... npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error npm error While resolving: fullstack-react-node@0.1.0 npm error Found: react@19.0.0 npm error node_modules/react npm error react@"^19.0.0" from the root project npm error npm error Could not resolve dependency: npm error peer react@"^18.0.0" from @testing-library/react@13.4.0 npm error node_modules/@testing-library/react npm error @testing-library/react@"^13.0.0" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution. npm error npm error npm error For a full report see: npm error C:\Users\Davi\AppData\Local\npm-cache_logs\2024-12-18T16_52_19_479Z-eresolve-report.txt npm error A complete log of this run can be found in: C:\Users\Davi\AppData\Local\npm-cache_logs\2024-12-18T16_52_19_479Z-debug-0.log npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0 failed

Imagem do visual studio code copntendo erro descrito acima no terminal

4 respostas

Olá, Davi, como vai?

O erro que você está encontrando é causado por um conflito entre as versões do React e do @testing-library/react. O React 19.0.0 foi instalado automaticamente pelo Create React App, mas a biblioteca @testing-library/react@13.4.0 exige o React 18.0.0 como dependência peer.

Como resolver:

1 - Utilizar uma versão estável do React 18, já que o React 19 ainda é recente. Execute o seguinte comando para corrigir a versão do React:

npm install react@18 react-dom@18

2 - Recriar o projeto com uma versão específica do React: Caso queira começar do zero, use:

npx create-react-app nome-do-projeto --template cra-template@1.1.2

O ideal é usar a versão 18 do React, que é totalmente suportada pelas bibliotecas atuais. Isso evita conflitos e mantém o ambiente estável.

Espero ter ajudado!

Siga firme nos seus estudos e conte com o fórum sempre que precisar!

Abraços :)

Caso este post tenha lhe ajudado, por favor, marcar como solucionado

oi! infelizmente não funcionou, eu instalei o react 18 mas continuou no erro C:\Users\Davi\Desktop\fullstack> npm install react@18 react-dom@18

added 4 packages, changed 1 package, and audited 6 packages in 10s

found 0 vulnerabilities PS C:\Users\Davi\Desktop\fullstack> npx create-react-app .

Creating a new React app in C:\Users\Davi\Desktop\fullstack.

Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts with cra-template...

added 1319 packages in 4m

264 packages are looking for funding run npm fund for details

Initialized a git repository.

Installing template dependencies using npm... npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error npm error While resolving: fullstack@0.1.0 npm error Found: react@19.0.0 npm error node_modules/react npm error react@"^19.0.0" from the root project npm error npm error Could not resolve dependency: npm error peer react@"^18.0.0" from @testing-library/react@13.4.0 npm error node_modules/@testing-library/react npm error @testing-library/react@"^13.0.0" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution. npm error npm error npm error For a full report see: npm error C:\Users\Davi\AppData\Local\npm-cache_logs\2024-12-21T22_21_52_281Z-eresolve-report.txt npm error A complete log of this run can be found in: C:\Users\Davi\AppData\Local\npm-cache_logs\2024-12-21T22_21_52_281Z-debug-0.log npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0 failed PS C:\Users\Davi\Desktop\fullstack

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Correção: consegui instalar com a segunda opção instalando do zero, porém, deu 10k de atualizações do git e apareceram vulerabilidades, isso é um problema?

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Oi, Davi.

As atualizações do git são referentes aos pacotes da pasta node_modules, o arquivo .gitignore normalmente já é preparado para lidar com isso e não vai deixar a pasta subir para o github, as vulnerabilidades não devem interferir no andamento do projeto. Talvez a única atualização necessária seja no arquivo index.js.

Caso o projeto base não renderize, tente atualizar o código da seguinte forma:

import React from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const container = document.getElementById('root');
const root = createRoot(container);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

Se ainda houver dúvidas ou precisar de ajuda com algo mais, não hesite em me chamar!

Bons estudos!