简体   繁体   English

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

[英]Flutter Web: Missing main.dart.js and JavaScript files when building with flutter build web, but working fine with flutter run

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 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.我目前在版本 1.18.0 beta 通道上,每个项目都会发生这种情况,即使 Flutter 使用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.不会引发任何警告或错误,如果我使用flutter run --release -d chrome web 项目,一切都会按预期工作。

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. 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.我的 Flutter 配置和 SDK 似乎就位。 This is what I get if I run flutter doctor -v如果我运行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?为什么没有生成 JavaScripts 文件?

Please check the following folder:请检查以下文件夹:

./your-app/build/web

I had the same problem and was checking the wrong folder ( ./your-app/web ).我遇到了同样的问题,并且正在检查错误的文件夹( ./your-app/web )。

  1. make sure to copy files, from:确保从以下位置复制文件:
    ./your-app/build/web

  2. If the error still exists, update the index.html如果错误仍然存在,请更新索引。html
    Example:例子:
    a.一个。 my flutter project at web server: webserver/flutter_project/index.html我在 web 服务器上的 flutter 项目: webserver/flutter_project/index.html
    b.湾。 open the index.html打开索引。html
    c. c。 update <base href="/"> to <base href="/flutter_project/"><base href="/">更新为<base href="/flutter_project/">

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 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 文档

The simplest thing that worked for me is updating to <base href="./"> from <base href="/"> .对我有用的最简单的事情是从<base href="/">更新到<base href="./"> > 。 So current path instead of root所以当前路径而不是根

In my case (IIS).json files are available in my directory but are not published by the web server.在我的情况下 (IIS).json 文件在我的目录中可用,但不是由 web 服务器发布。 I had to add MIME types to allow them.我必须添加 MIME 类型以允许它们。 Same question for.otf files. .otf 文件的相同问题。

In my case, the flutter.js file is not generated when building for web.在我的情况下,为 web 构建时不会生成flutter.js文件。 What I do is run flutter clean then run flutter build web again.我要做的是运行flutter clean然后运行flutter build web You should see the missing js file and make sure to check on build/web not web on the root.您应该会看到缺少的 js 文件,并确保在根目录上检查build/web而不是web

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM