-1

Eu estava desenvolvendo um projeto em react para web, tudo normal, e sem explicação no dia seguinte não conseguia mais executar a aplicação com npm start ou yarn start.

Segue meu package.json e o erro retornado após yarn start.

package.json

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.19.2",
    "npm": "^6.14.3",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Erro retornado

yarn run v1.22.1
warning ../../../package.json: No license field
$ react-scripts start

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:

  "webpack": "4.42.0"

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

  /home/ricardo/node_modules/webpack (version: 4.39.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 "webpack" 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/ricardo/node_modules/webpack is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

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

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!

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Não entendo o motivo desse erro, uma vez que eu não mexi em parte nenhuma do sistema ou do projeto. Agradeço a ajuda.

3 Respostas 3

2

Também tive este problema, encontrei uma solução aqui, basicamente você vai precisar criar um arquivo na raiz .env(lembre-se que não deve ter nome o arquivo, é somente a extensão dele) e nele colocar a seguinte linha de código:

SKIP_PREFLIGHT_CHECK=true

Logo após funcionou normalmente aqui.

-1

Problema era que, também havia uma pasta node_modules na raiz do sistema. Não sei por qual motivo estava impedindo o funcionamento, mas assim que a apaguei, voltou a funcionar!

-3

Gente, no meu caso eu só estava na pasta errada.

Quando eu pedia pra rodar estava na pasta "ToDoList". Eu criei o projeto do react dentro dela chamado "cursoreact".

O npm start estava abrindo a pasta ToDoList e não encontrava nada, então eu usei o comando "cd" e entrei na pasta cursoreact e ai o npm start funcionou.

segue exemplo:

C:\Users\julia\OneDrive\Área de Trabalho\toDoList> npm start

dir = pra ver as pastas dentro dela

cd cursoreact = entrei na pasta

C:\Users\julia\OneDrive\Área de Trabalho\toDoList\cursoreact>npm start

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .