Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter web warns that serviceWorkerVersion or the service worker is deprecated

ErrorLocal 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.

  • Applies to Flutter 3.35, Dart 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.html
  2. 2Match what you see, then jump to its fix

    1. 1Local variable for "serviceWorkerVersion" is deprecatedA leftover serviceWorkerVersion variable in index.htmlFix
    2. 2Warning: In index.html: Flutter's service worker is deprecatedA hand-written service worker registrationFix
    3. 3Warning: In index.html: Flutter's service worker is deprecatedserviceWorkerSettings passed to the loaderFix
    4. 4"FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead.An old index.html that still calls loadEntrypointFix

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.html

2Fix

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 web

Confirmed by docs.flutter.dev

Did this fix it?

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.html

2Fix

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 web

Confirmed by docs.flutter.dev

Did this fix it?

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 8080

Confirmed by docs.flutter.dev

Did this fix it?

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.html

2Fix

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.js

Confirmed by docs.flutter.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.