首页 > 解决方案 > Flutter App to Web 通过 Github 页面黑屏

问题描述

我有一个由 Flutter-Web 商店生成的页面,它是一个空白页面。我在控制台中有一个错误。这是在将 Flutter 的构建 Web 上传到 GitHub Pages 之后发生的。

Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('https://adamtechnologynl.github.io/') with script ('https://adamtechnologynl.github.io
/flutter_service_worker.js?v=2470069411'): A bad HTTP response code (404) was received when fetching the script.
manifest.json:1 Failed to load resource: the server responded with a status of 404 ()
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.
manifest.json:1 Failed to load resource: the server responded with a status of 404 ()
(index):88 Failed to load app from service worker. Falling back to plain <script> tag.
(anonymous) @ (index):88
(index):47 GET https://adamtechnologynl.github.io/main.dart.js net::ERR_ABORTED 404
loadMainDartJs @ (index):47
(anonymous) @ (index):91

标签: htmlgithub-pagesflutter-web

解决方案


我找到了解决方案。当您将其放在另一个目录而不是 GitHub 的根目录时,就会发生这种情况。

所以我的代码在“https://username.github.io/demo/book-king/belasting-web-v1/”中,所以最后一部分我们应该在“https://username.github.io/”之后附加所有内容也在 index.html 中。您可以通过修改行来解决它(我的第 17 行):

改变:

<base href="/">

进入:

<base href="/demo/book-king/belasting-web-v1/">

然后你就完成了。


推荐阅读