Flutter web warns that serviceWorkerVersion or the service worker is deprecated
Local variable for "serviceWorkerVersion" is deprecated.Short answer
Flutter no longer generates or registers a caching service worker, so the old variable and loader settings in web/index.html are now flagged. Delete the serviceWorkerVersion line, the service worker registration call and the serviceWorkerSettings block, and let flutter_bootstrap.js start the app.
Fix it fast
1Find out which cause you have
Open web/index.html and search for the old loader pieces. The line number in the warning points to the one to change.
grep -n -E "serviceWorker|loadEntrypoint|flutter_bootstrap" web/index.html2Match what you see, then jump to its fix
- 1
Local variable for "serviceWorkerVersion" is deprecatedA leftover serviceWorkerVersion variable in index.htmlFix - 2
Warning: In index.html: Flutter's service worker is deprecatedA hand-written service worker registrationFix - 3
Warning: In index.html: Flutter's service worker is deprecatedserviceWorkerSettings passed to the loaderFix - 4
"FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead.An old index.html that still calls loadEntrypointFix
- 1
What does the error look like?
Local variable for "serviceWorkerVersion" is deprecated.Warning: In index.html:37: Flutter's service worker is deprecated and will be removed in a future Flutter release.Warning: In index.html:40: "FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead.
Cause 1 of 4
A leftover serviceWorkerVersion variable in index.html
1Check
Older project templates declared the variable in an inline script in web/index.html. The loader no longer reads it.
grep -n "serviceWorkerVersion" web/index.html2Fix
Delete the declaration. The Flutter docs list both forms, var and const, as legacy lines to remove.
// delete this line from web/index.html
var serviceWorkerVersion = null;3Verify
Rebuild and check that the warning is gone.
flutter build webConfirmed by docs.flutter.dev
Cause 2 of 4
A hand-written service worker registration
1Check
Some pages register flutter_service_worker.js themselves with navigator.serviceWorker.register.
grep -n "serviceWorker.register" web/index.html2Fix
Remove the registration call. Flutter no longer generates a caching service worker, so there is nothing to register.
// delete this call
navigator.serviceWorker.register('flutter_service_worker.js');3Verify
Rebuild, then reload the site with DevTools open (Application tab) and confirm no new Flutter service worker is registered.
flutter build webConfirmed by docs.flutter.dev
Cause 3 of 4
serviceWorkerSettings passed to the loader
1Check
A custom start-up script, either in index.html or in web/flutter_bootstrap.js, passes serviceWorkerSettings with the {{flutter_service_worker_version}} token. That token is marked deprecated.
grep -rn "serviceWorkerSettings\|flutter_service_worker_version" web/2Fix
Call the loader without the settings block.
{{flutter_js}}
{{flutter_build_config}}
_flutter.loader.load();3Verify
Build and open the app through a local server.
flutter build web
cd build/web && python3 -m http.server 8080Confirmed by docs.flutter.dev
Cause 4 of 4
An old index.html that still calls loadEntrypoint
1Check
Projects created before the flutter_bootstrap.js template keep the old script block, which calls _flutter.loader.loadEntrypoint.
grep -n "loadEntrypoint" web/index.html2Fix
For the default start-up, replace the whole old script block with the bootstrap script tag. For custom start-up, call load() instead.
<script src="flutter_bootstrap.js" async></script>3Verify
Rebuild; build/web should contain flutter_bootstrap.js and the app should start.
flutter build web
ls build/web/flutter_bootstrap.jsConfirmed by docs.flutter.dev
How do I stop it coming back?
- Treat web/index.html as generated-then-owned: after a Flutter upgrade, compare it with the template from a fresh flutter create project.
- Keep custom start-up code in web/flutter_bootstrap.js with the two tokens, not in scattered inline scripts.
- Read the warnings of flutter build web after every SDK upgrade.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix