Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack - net::ERR_ABORTED 404 (Not Found)

I am learning Webpack, after running Webpack with npm run build creating a bundle.js file, then importing the Post module, then exporting to Index.js file then including bundle.js file to index.html file, here is my code

Post.js

export default class Post {
    constructor(title) {
        this.title = title
        this.date = new Date()
    }

    toString() {
        return JSON.stringify({
            title: this.title,
            date: this.date.toJSON()
        })
    }
}

index.js

import Post from "./Post"

const post = new Post('Webpack Post Title')

console.log('Post to String', post.toString())

index.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="analytics.js"></script>
</head>
<body>
    <div class="container">
        <h1>Webpack Course</h1>
    </div>

    <script src="bundle.js"></script>
</body>
</html>

After that I open the file with live server and it gives an error

index.html

GET http://127.0.0.1:5500/src/bundle.js net::ERR_ABORTED 404 (Not Found)

Unchecked runtime.lastError: The message port closed before a response was received.

webpack.config.js

const path = require('path');

module.exports = {
    mode: "development",
    entry: "./src/index.js",
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    }
}

package.json

{
  "name": "tutorial-minin",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Suro Zakaryan",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^5.11.1",
    "webpack-cli": "^4.3.1"
  }
}
like image 766
Synchro Avatar asked Apr 21 '26 19:04

Synchro


1 Answers

Adding <base href="/"> to the your index.html head should fix the issue.

like image 93
Oladimeji Akande Avatar answered Apr 24 '26 09:04

Oladimeji Akande