I’m trying to run webpack
with my React Project, but when I run my project with the commend webpack-dev-serve
I get the error:
Cannot GET /
I try looking into the http://localhost:8080/webpack-dev-serve
to check if the routing to the build is incorrect but I don’t see a problem.
Can someone help me with this problem? I am looking around for hours now
webpack.config.js
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: './src/index.tsx',
devtool: 'eval-source-map',
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules:[
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [
{
loader:'babel-loader',
},
],
include:[path.resolve(__dirname, 'src')],
},{
test: /\.css$/,
use:['style-loader', 'css-loader'],
include:[path.resolve(__dirname, 'src')],
},{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
type:'asset/resource',
include:[path.resolve(__dirname, 'src')],
},
],
},
output: {
publicPath: '/build/',
filename: 'bundle.js',
path: path.resolve(__dirname, '/build/'),
},
mode: 'development',
plugins: [
new htmlWebpackPlugin({
template: path.resolve(__dirname, 'build', 'index.html')
}),
],
}
package.json
{
"name": "react-shopping-bag",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"serve": "webpack-dev-server",
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.15.8",
"@babel/plugin-transform-runtime": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@types/react": "^17.0.32",
"@types/react-dom": "^17.0.10",
"babel-loader": "^8.2.3",
"css-loader": "^6.4.0",
"html-webpack-plugin": "^5.4.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"style-loader": "^3.3.1",
"typescript": "^4.4.4",
"webpack": "^5.59.1",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.3.1"
}
}
http://localhost:8080/webpack-dev-server
http://localhost:8080/build/bundle.js