Flutter Web: Missing main.dart.js and JavaScript files when building with flutter build web, but working fine with flutter run
Asked Answered
R

7

9

I am running into an issue with Flutter web in which no JavaScript files are generated when running flutter build web in any project, causing prjects to simply load a blank page.

I am currently on version 1.18.0 beta channel, and this happens with every project, even with the default counter project that Flutter generates with flutter create .. No warnings or errors are thrown, and if I run the web project with flutter run --release -d chrome, everything works as intended.

I have followed the steps described in the Building a web application with Flutter article from the documentation, and I remember I was able to build and host a web project with Flutter half a year ago with no issues, following the same steps.

My Flutter configuration and SDKs seem to be in place. This is what I get if I run flutter doctor -v

[√] Flutter (Channel beta, 1.18.0-11.1.pre, on Microsoft Windows [Versión 10.0.18363.836], locale es-ES)
    • Flutter version 1.18.0-11.1.pre at D:\Programas\Flutter\flutter
    • Framework revision 2738a1148b (4 weeks ago), 2020-05-13 15:24:36 -0700
    • Engine revision ef9215ceb2
    • Dart version 2.9.0 (build 2.9.0-8.2.beta)


[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\diego\AppData\Local\Android\sdk
    • Platform android-28, build-tools 28.0.3
    • Java binary at: D:\Programas\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.6)
    • Android Studio at D:\Programas\Android Studio
    • Flutter plugin version 46.0.1
    • Dart plugin version 192.8052
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] Connected device (2 available)
    • Web Server • web-server • web-javascript • Flutter Tools
    • Chrome     • chrome     • web-javascript • Google Chrome 83.0.4103.61

What might be wrong here? Why are no JavaScripts files being generated?

Resect answered 7/6, 2020 at 20:13 Comment(0)
D
33

Please check the following folder:

./your-app/build/web

I had the same problem and was checking the wrong folder (./your-app/web).

Dynast answered 6/7, 2020 at 14:54 Comment(2)
True! In the end I figured that out and forgot about this question, so I did not update it, but indeed I was looking in the wrong place. Thanks!Resect
I am getting same error when running from myapp/build/web/index.html. It has main.dart.js file but still reports the error. It seems it is looking for the fine in directly in the root directory file:///D:/main.dart.js instead of the same web folder.Constriction
A
9
  1. make sure to copy files, from:
    ./your-app/build/web

  2. If the error still exists, update the index.html
    Example:
    a. my flutter project at web server: webserver/flutter_project/index.html
    b. open the index.html
    c. update <base href="/"> to <base href="/flutter_project/">

Arwood answered 11/4, 2021 at 16:35 Comment(1)
You can also update <base href="/"> in web/index.html instead of in build/web/index.html, so that the source index.html file contains the correct base path. This works with flutter run and flutter build web.Mcvay
F
6

In my case, the flutter.js file is not generated when building for web. What I do is run flutter clean then run flutter build web again. You should see the missing js file and make sure to check on build/web not web on the root.

Freudberg answered 5/8, 2022 at 17:11 Comment(1)
I have the same issue and don't know the root cause.Richards
H
1

For those who cant open builded version: Go to 'app/build/web' and run a server from there python -m http.server 8000, or by using the dhttpd package

Docs

Halhalafian answered 20/3, 2021 at 20:14 Comment(0)
L
1

My issue was that .gitignore had *.dart.js, which didn't allow main.dart.js file to upload to the repository.

As I have my deployment path as /dist/web, I added the following exception:

!/dist/**

So every file from that path uploads.

Lens answered 8/8, 2023 at 23:36 Comment(0)
U
0

The simplest thing that worked for me is updating to <base href="./"> from <base href="/">. So current path instead of root

Unhesitating answered 16/6, 2021 at 12:30 Comment(0)
C
0

In my case (IIS) .json files are available in my directory but are not published by the web server. I had to add MIME types to allow them. Same question for .otf files.

Cayes answered 15/7, 2021 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.