Estou tentando criar minha primeira aplicação ReactJS.
Quando executo no terminal bash do VSCode o seguinte comando:
yarn webpack-dev-server --mode development
Aparece o seguinte erro:
$ yarn webpack-dev-server --mode development
yarn run v1.22.10
$ C:\tools\Cmder\react\node_modules\.bin\webpack-dev-server --mode development
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- C:\tools\Cmder\react\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> (C:\tools\Cmder\react\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: [
'C:\\tools\\Cmder\\react\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Já tentei colocar todos scripts no package.json
que vi no stackoverflow e já instalei o yarn
de diversas formas.
Meu webpack.config.js está assim:
const path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src', 'index.js'),
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js'
},
devServer: {
contentBase: path.resolve(__dirname, 'public'),
},
module: {
rules:[
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader:'babel-loader',
}
}
]
}
};