Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

javascript - 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"
  }
}
question from:https://stackoverflow.com/questions/65602912/webpack-neterr-aborted-404-not-found

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...