4
respostas

devServer - npm start dando erro

Olá! Estou na aula da trilha de react "criando DevServer" do assunto webpack e quando tento rodar o npm start aparece o seguinte erro! Podem me ajudar?

> petshop@1.0.0 start
> webpack-dev-server --config ./webpack.config.js --mode development

node:internal/modules/cjs/loader:928
  throw err;
  ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- /home/camilal/Área de Trabalho/projeto/node_modules/webpack-dev-server/bin/webpack-dev-server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/home/camilal/Área de Trabalho/projeto/node_modules/webpack-dev-server/bin/webpack-dev-server.js:65:1)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/camilal/Área de Trabalho/projeto/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
  ]
}
npm ERR! code 1
npm ERR! path /home/camilal/Área de Trabalho/projeto
npm ERR! command failed
npm ERR! command sh -c webpack-dev-server --config ./webpack.config.js --mode development

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/camilal/.npm/_logs/2020-12-18T20_05_09_095Z-debug.log
4 respostas

Oi Camila Creio que baste atualizar a versão do webpack para a última!

npm install webpack-config --save-dev

Olá!

Eu já estava utilizando a última versão e o problema persiste :/

Instalou na pasta correta do projeto?

Olá Camila, tive o mesmo problema, consegui resolver trocando o comando webpack-dev-server por webpack serve, ficando assim:

webpack serve --config webpack.config.js --mode development

fonte: https://github.com/webpack/webpack-dev-server/blob/master/README.md#with-npm-scripts