shelf
shelf copied to clipboard
Flutter web deployment: Failed to load app from service worker. Falling back to plain <script> tag. (anonymous) @ (index):91
Hello
I try to deploy flutter web app using shelf
import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';
void main(List<String> args) async {
final path = r'<PATH-TO-PROJECT>\build\web';
final pipeline = const Pipeline()
.addMiddleware(logRequests())
.addHandler(createStaticHandler(path, defaultDocument: 'index.html'));
await io.serve(pipeline, InternetAddress.anyIPv4, 8080);
}
when I run app an entering localhost:8080
the website not showing, and throw this error on chrome console:
New service worker available.
(index):91 Failed to load app from service worker. Falling back to plain <script> tag.
(anonymous) @ (index):91
main.dart.js:26459 NoSuchMethodError: method not found: 'db' on null
main.dart.js:26459 at ZS.$1$3$instanceName$param1$param2 (http://localhost:8080/main.dart.js:82445:73)
main.dart.js:26459 at ZS.$0 (http://localhost:8080/main.dart.js:82451:18)
main.dart.js:26459 at aeN.$2 (http://localhost:8080/main.dart.js:83261:29)
main.dart.js:26459 at pX.agu (http://localhost:8080/main.dart.js:78543:24)
main.dart.js:26459 at GP.E (http://localhost:8080/main.dart.js:78577:18)
main.dart.js:26459 at fo.bQ (http://localhost:8080/main.dart.js:71326:29)
main.dart.js:26459 at fo.j8 (http://localhost:8080/main.dart.js:71297:9)
main.dart.js:26459 at fo.j8 (http://localhost:8080/main.dart.js:71336:10)
main.dart.js:26459 at fo.up (http://localhost:8080/main.dart.js:71265:6)
main.dart.js:26459 at fo.c2 (http://localhost:8080/main.dart.js:71345:36)
main.dart.js:26459 Another exception was thrown: Instance of 'minified:jw<void>'
(index):65 Installed new service worker.
Console of browser
Why version of Flutter/Dart are you using?
Closing w/ no response.
@kevmoo, flutter version is:
[√] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.22000.556], locale en-US)
• Flutter version 2.10.3
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7e9793dee1 (4 weeks ago), 2022-03-02 11:23:12 -0600
• Engine revision bd539267b4
• Dart version 2.16.1
• DevTools version 2.9.2
I managed to get Flutter for web working. Did you try something like this?
var cascadeHandler = Cascade().add(createStaticHandler('web', defaultDocument: 'index.html')).add(apiRouter).handler;