Flutter web 发布模式错误
Flutter web release mode errors
我有一个 flutter 应用程序,它 运行 在 flutter web 上以调试模式正常运行,
然后我 运行 使用此命令在发布和配置文件模式下使用相同的应用程序
flutter run -d chrome --release
它给出了一个白屏,我打开了 chrome 控制台,它给出了这个不明确的错误
无法理解:
zone.dart:1339 Uncaught FormatException: SyntaxError: Unexpected token < in JSON at position 0
at Object.c (http://localhost:6282/main.dart.js:4084:3)
at Object.bjN (http://localhost:6282/main.dart.js:6909:9)
at WI.tW (http://localhost:6282/main.dart.js:49640:28)
at WI.J (http://localhost:6282/main.dart.js:49642:29)
at http://localhost:6282/main.dart.js:125497:12
at bd3.a (http://localhost:6282/main.dart.js:5826:71)
at bd3. (http://localhost:6282/main.dart.js:46749:23)
at bbV. (http://localhost:6282/main.dart.js:46741:30)
at a8F.rs (http://localhost:6282/main.dart.js:48088:42)
at aWK.[=10=] (http://localhost:6282/main.dart.js:47231:11)
编辑1: flutter doctor详细日志为:
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19042.1055], locale en-US)
• Flutter version 2.2.3 at C:\flutter
• Framework revision f4abaa0735 (10 days ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\ASUS\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[√] VS Code (version 1.55.2)
• VS Code at C:\Users\ASUS\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.21.0
[√] Connected device (3 available)
• Redmi Note 8 Pro (mobile) • pns4zlqkivhu9psk • android-arm64 • Android 10 (API 29)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.124
• Edge (web) • edge • web-javascript • Microsoft Edge 86.0.622.38
! Doctor found issues in 1 category.
Edit2: 调试模式下的 flutter 应用程序在 chrome 控制台中给出了这些错误,但它正常工作:
GET https://apidev2.koutbo6.com/2.0/online_status/room/1-02162-0/ 401
GET https://dev.koutbo6.com/site_media/avatars/table_image/default/koutbo4.png 404
但是,它与图像有关,我认为这不是问题的原因。
经过很长时间的研究,我发现这个问题与一个名为 time_machine 的外部包有关,导致这个问题的原因只是它在 web 平台中的初始化步骤。
我有一个 flutter 应用程序,它 运行 在 flutter web 上以调试模式正常运行,
然后我 运行 使用此命令在发布和配置文件模式下使用相同的应用程序
flutter run -d chrome --release
它给出了一个白屏,我打开了 chrome 控制台,它给出了这个不明确的错误
无法理解:
zone.dart:1339 Uncaught FormatException: SyntaxError: Unexpected token < in JSON at position 0
at Object.c (http://localhost:6282/main.dart.js:4084:3)
at Object.bjN (http://localhost:6282/main.dart.js:6909:9)
at WI.tW (http://localhost:6282/main.dart.js:49640:28)
at WI.J (http://localhost:6282/main.dart.js:49642:29)
at http://localhost:6282/main.dart.js:125497:12
at bd3.a (http://localhost:6282/main.dart.js:5826:71)
at bd3. (http://localhost:6282/main.dart.js:46749:23)
at bbV. (http://localhost:6282/main.dart.js:46741:30)
at a8F.rs (http://localhost:6282/main.dart.js:48088:42)
at aWK.[=10=] (http://localhost:6282/main.dart.js:47231:11)
编辑1: flutter doctor详细日志为:
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19042.1055], locale en-US)
• Flutter version 2.2.3 at C:\flutter
• Framework revision f4abaa0735 (10 days ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\ASUS\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[√] VS Code (version 1.55.2)
• VS Code at C:\Users\ASUS\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.21.0
[√] Connected device (3 available)
• Redmi Note 8 Pro (mobile) • pns4zlqkivhu9psk • android-arm64 • Android 10 (API 29)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.124
• Edge (web) • edge • web-javascript • Microsoft Edge 86.0.622.38
! Doctor found issues in 1 category.
Edit2: 调试模式下的 flutter 应用程序在 chrome 控制台中给出了这些错误,但它正常工作:
GET https://apidev2.koutbo6.com/2.0/online_status/room/1-02162-0/ 401
GET https://dev.koutbo6.com/site_media/avatars/table_image/default/koutbo4.png 404
但是,它与图像有关,我认为这不是问题的原因。
经过很长时间的研究,我发现这个问题与一个名为 time_machine 的外部包有关,导致这个问题的原因只是它在 web 平台中的初始化步骤。