2
respostas

[Bug] Teste não executa. Erro de dependências

Quando tento executar o teste aparece o seguinte:

renan@vortex:~/Github/bytebank$ npm run test

> bytebank@0.1.0 test
> react-scripts test


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.

The react-scripts package provided by Create React App requires a dependency:

  "eslint": "^5.16.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of eslint was detected higher up in the tree:

  /home/renan/Github/bytebank/node_modules/eslint (version: 7.32.0) 

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 .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "eslint" 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.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /home/renan/Github/bytebank/node_modules/eslint is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls eslint in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed eslint.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

Então fiz o que manda e tive o seguinte erro:

renan@vortex:~/Github/bytebank$ npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: bytebank@0.1.0
npm ERR! Found: eslint@5.16.0
npm ERR! node_modules/eslint
npm ERR!   dev eslint@"^5.16.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@">=7.0.0" from eslint-config-prettier@9.1.0
npm ERR! node_modules/eslint-config-prettier
npm ERR!   dev eslint-config-prettier@"^9.1.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/renan/.npm/_logs/2024-04-08T17_48_03_182Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/renan/.npm/_logs/2024-04-08T17_48_03_182Z-debug-0.log

Apaguei novamente a node_modules e mudei a versão do eslint para a 7 e o primeiro erro voltou a acontecer.

Pq ainda usar CRA se ele já está descontinuado?

2 respostas

ola amigo, esse não é bem um erro sabe? é mais um aviso, então indico que você não mexa nisso senão vai ocorrer erro de verdade, como você viu!

pra tirar esses avisos, você pode optar por ignorar este aviso adicionando SKIP_PREFLIGHT_CHECK=true a um arquivo .env

ah e usam CRA ainda pq muitas equipes ainda usam o CRA pq ele oferece uma maneira fácil e rápida de configurar um projeto React com um conjunto de ferramentas padrão abraços!

Fiz o que você disse e ainda assim o script continua não funcionando:

> bytebank@0.1.0 lint /home/renan/Github/bytebank
> eslint "src/**/*{.js,.jsx}" --quiet


Oops! Something went wrong! :(

ESLint: 9.0.0

Error: Could not find config file.
    at locateConfigFileToUse (/home/renan/Github/bytebank/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/eslint/eslint.js:349:21)
    at async calculateConfigArray (/home/renan/Github/bytebank/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/eslint/eslint.js:384:49)
    at async ESLint.lintFiles (/home/renan/Github/bytebank/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/eslint/eslint.js:814:25)
    at async Object.execute (/home/renan/Github/bytebank/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/cli.js:461:23)
    at async main (/home/renan/Github/bytebank/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/bin/eslint.js:165:22)
 ELIFECYCLE  Command failed with exit code 2.