我正在开发 Flutter Web App,今天我遇到了以下错误:
A bad HTTP response code (404) was received when fetching the script.
Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('https://adrieldf.github.io/') with script ('https://adrieldf.github.io/flutter_service_worker.js'): A bad HTTP response code (404) was received when fetching the script.
我添加到代码中的唯一“不同”是 Share 库的依赖项,但我认为这不是问题所在。
有趣的是,我将应用托管在 Github Pages 上,每次提交后,我都有一个构建 Web 应用的操作。构建后,当我尝试访问它时,它不会加载并出现错误。但是在本地构建并运行它可以正常工作。
如果你想检查,这里是源代码:https://github.com/Adrieldf/allthewidgets
网站链接在 repo 说明中。
最佳答案
好吧,问题在于错误消息所说的内容。您的 JS 正在尝试从脚本“https://adrieldf.github.io/flutter_service_worker.js ”注册一个 Service Worker,但该脚本在服务器上不存在。如果您打开该 URL,则它是 404。
关于web - 注册 ServiceWorker 失败(Flutter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60675954/