没有找到包文件

Bundle file not found

本文关键字:文件 包文件      更新时间:2023-09-26

让我的整个应用程序启动并工作,创建了一个新页面,它找不到它

app.js:

app.get('/logged_in', function (req, res) {
  res.sendFile(__dirname + '/logged_in.html');
});

webpack.config.is

  output: {
    path: path.resolve(__dirname, 'public'),
    filename: "[name].bundle.js"
  },

现在被添加到app.js:

app.get('/messaging', function (req, res) {
  res.sendFile(__dirname + '/messaging.html');
});

和我得到一个错误:http://localhost:3000/messaging.bundle.js 404 (Not Found)

最后一件事:

在我的html文件中有

logged_in.html> <script src="logged_in.bundle.js"></script>message .html> <script src="messaging.bundle.js"></script>

不知道为什么不工作

我不知道你使用的是哪个框架,在express中你应该使用app.use(express.static(...))来为客户端提供静态文件

您可以查看此文档以获取更多信息:http://expressjs.com/en/starter/static-files.html


的例子:

如果您将bundle.js放在dist中,而dist位于项目的根目录下。如果你想为客户端提供bundle.js,你应该将bundle.js或包含bundle.js的文件夹设置为静态。

app.use('/static', express.static(`${__dirname}/dist`))

则可以使用http://localhost:3000/static/bundle.js在客户端获取bundle.js