When I go to my website, “example.com” I receive this error:
We recenently had HTTPS setup so that may be the problem, but for now I’ve tried the following:
- Flutter clean and building the application again
- Made base href “./“ instead of “/"
- Tried adding main.dart.js file to index.html as script
- Accessing website from mobile and desktop
- Accessing website from HTTP, HTTPS, and WWW
- Accessing on a new device to see if it was a caching problem (it was not)
Here is my index.html file:
<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>
<body>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
}
}).then(function(engineInitializer) {
return engineInitializer.initializeEngine();
}).then(function(appRunner) {
return appRunner.runApp();
});
});
</script>
</body>
Here is my flutter doctor logs:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.1, on macOS 13.1 22C65 darwin-arm64, locale
en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] Connected device (5 available)
[✓] HTTP Host Availability
Thanks
EDIT: I uploaded the site to firebase and it worked fine so I have a feeling it has to do with HTTPS recently being setup.
2
Answers
After messing with the flutter.js file with no fix, I reverted to running
flutter clean
andflutter build web
3 times and it is finally fixed and my site is now working as normal. Weird bug.Replacing this line
With
Will resolve the issue as flutter build web doesn’t produces flutter.js