Flutter web debug is working but build web shows a blank page
Asked Answered
E

5

7

flutter doctor result

[√] Flutter (Channel dev, 1.21.0-1.0.pre, on Microsoft Windows [Version 10.0.19041.388], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.0)
[√] VS Code (version 1.47.2)
[√] Connected device (3 available)

• No issues found!

I was working with flutter v 1.20-7.2.pre in beta channel and encountered this problem. So I switched to dev channel.

I tried running the example project (boilerplate) as well and got a blank page. The console shows some errors in main.dart.js and js_helper.dart shows the error:

Could not load content for org-dartlang-sdk:///lib/_internal/js_runtime/lib/js_helper.dart (HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME)

To Reproduce the problem

Create the sample project in any IDE Run the following commands:

flutter channel beta
flutter upgrade
flutter config --enable-web

OR

flutter channel dev
flutter upgrade
flutter config --enable-web

Then, run: flutter build web

After this, I used python to run localhost: python -m http.server 8080 in the $root_folder\build\web

I found another answer which suggested hosting the build\web folder as localhost has CORS problems

Also, I tried using the debug mode: flutter run -d Chrome and it worked!

Extra information: I am testing this on Chrome v 84.0.4147.89 (Official Build) (64-bit)

Eau answered 23/7, 2020 at 5:18 Comment(0)
E
4

Found answers to this question here. It was actually happening due to firebase and was not a flutter issue at all.

Eau answered 23/7, 2020 at 15:33 Comment(0)
M
1

Must run a server.

dart pub global activate dhttpd

dart pub global run dhttpd --path build/web/
Marybethmaryellen answered 17/5, 2022 at 18:44 Comment(0)
B
1

Just remove the below line from the index.html

<base href="/">

Brainy answered 25/10, 2023 at 7:13 Comment(0)
P
0

Try

flutter build web --base-href=/build/web/

so that the base href matches with the directory structure of your dev machine.

Do not forge you need to rebuild it

flutter build web

when you deploy it to the hosting site.

Pruritus answered 25/3, 2023 at 20:5 Comment(0)
O
0

Can't run when building web

to load resource: net::ERR_FILE_NOT_FOUND cess to internal resource at 'file:///F:/user/Flutter%20Projects/web-app/web/manifest.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

Odonnell answered 9/5, 2023 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.