【问题标题】:Flutter web - the server responded with a status of 404 (Not Found), main.dart.js:1Flutter web - 服务器响应状态为 404(未找到),main.dart.js:1
【发布时间】:2021-05-08 09:50:13
【问题描述】:

Flutter web 项目在直接从 IDE 运行到 chrome 时运行顺利,但在调用 flutter build web 后,托管构建的 web 应用程序没有打开(只有一个空白页面)并显示此错误

Failed to load resource: the server responded with a status of 404 (Not Found)
main.dart.js:1 

Failed to load resource: the server responded with a status of 404 (Not Found)
(index):1 

Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('http://localhost:8080/') with script ('http://localhost:8080/flutter_service_worker.js'): A bad HTTP response code (404) was received when fetching the script.

【问题讨论】:

  • 您是说您托管了该应用程序吗?就像在不在本地的网络服务器上一样?
  • 是的,我在本地托管
  • 好吧,我猜这个问题是由于在 URL 中使用了“localhost”,但如果它仍然在本地托管,那么这不是问题。

标签: flutter dart flutter-web


【解决方案1】:

您发布的资源不是/build/web 而是/web

【讨论】:

  • 实际上托管/build/web 内部的那个有效,但/web 内部的那个不行?为什么会这样?
  • /web 文件不是真正的资源,它只是为构建配置
猜你喜欢
  • 2018-06-30
  • 2021-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2015-12-01
相关资源
最近更新 更多