firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

🐛 [firebase_core, analytics, firestore, auth etc] Web app crashes on load when not using firebase config in index.html #3962

Closed devjeff closed 2 years ago

devjeff commented 3 years ago

Bug report

The Readme for the FlutterFire plugins that support the web, indicate that you can either setup the FirebaseApp in index.html, or in Dart using package:firebase_core methods.

However, firebase_analytics_web crashes on application load when a default app has not been initialised in index.html. From what I can see, this is because the implementation of cloud_firestore_web tries to access the default firebase app when it is constructed as part of plugin registration.

This is actually the same issue, as this one here concerning the cloud firestore plugin.

Steps to reproduce

Steps to reproduce the behavior:

  1. Take a project with Flutter Web enabled and a dependency to the firebase analytics package.
  2. Comment-out the firebaseApp initialization in index.html. The FirebaseApp configuration in main.dart is still present.
  3. Run the app for web flutter run -d chrome.

App fails to load with the following error:

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
    at f (https://www.gstatic.com/firebasejs/7.16.0/firebase-app.js:1:16815)
    at Object.i [as analytics] (https://www.gstatic.com/firebasejs/7.16.0/firebase-app.js:1:17072)
    at Object.analytics$ [as analytics] (http://localhost:60018/packages/firebase/src/top_level.dart.lib.js:110:102)
    at new firebase_analytics_web.FirebaseAnalyticsWeb.new (http://localhost:60018/packages/firebase_analytics_web/firebase_analytics_web.dart.lib.js:56:64)
    at Function.registerWith (http://localhost:60018/packages/firebase_analytics_web/firebase_analytics_web.dart.lib.js:19:82)
    at Object.registerPlugins (http://localhost:60018/packages/craftsmen_mobile_client/generated_plugin_registrant.dart.lib.js:23:49)
    at main (http://localhost:60018/web_entrypoint.dart.lib.js:29:35)
    at main.next (<anonymous>)
    at runBody (http://localhost:60018/dart_sdk.js:37920:34)
    at Object._async [as async] (http://localhost:60018/dart_sdk.js:37951:7)
    at main (http://localhost:60018/web_entrypoint.dart.lib.js:28:18)
    at http://localhost:60018/main_module.bootstrap.js:20:10
    at Array.forEach (<anonymous>)
    at window.$dartRunMain (http://localhost:60018/main_module.bootstrap.js:19:32)
    at <anonymous>:1:8
    at Object.runMain (http://localhost:60018/dwds/src/injected/client.js:8764:21)
    at http://localhost:60018/dwds/src/injected/client.js:22538:19
    at _wrapJsFunctionForAsync_closure.$protected (http://localhost:60018/dwds/src/injected/client.js:3793:15)
    at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:60018/dwds/src/injected/client.js:11010:12)
    at Object._asyncStartSync (http://localhost:60018/dwds/src/injected/client.js:3757:20)
    at main__closure1.$call$body$main__closure (http://localhost:60018/dwds/src/injected/client.js:22550:16)
    at main__closure1.call$1 (http://localhost:60018/dwds/src/injected/client.js:22477:19)
    at StaticClosure._rootRunUnary [as call$2$5] (http://localhost:60018/dwds/src/injected/client.js:4124:16)
    at _CustomZone.runUnary$2$2 (http://localhost:60018/dwds/src/injected/client.js:12315:39)
    at _CustomZone.runUnaryGuarded$1$2 (http://localhost:60018/dwds/src/injected/client.js:12247:14)
    at _ControllerSubscription._sendData$1 (http://localhost:60018/dwds/src/injected/client.js:11798:19)
    at _DelayedData.perform$1 (http://localhost:60018/dwds/src/injected/client.js:11950:59)
    at _PendingEvents_schedule_closure.call$0 (http://localhost:60018/dwds/src/injected/client.js:11999:14)
    at Object._microtaskLoop (http://localhost:60018/dwds/src/injected/client.js:3960:24)
    at StaticClosure._startMicrotaskLoop (http://localhost:60018/dwds/src/injected/client.js:3966:11)
    at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1 (http://localhost:60018/dwds/src/injected/client.js:10879:9)
    at invokeClosure (http://localhost:60018/dwds/src/injected/client.js:1204:26)
    at MutationObserver.<anonymous> (http://localhost:60018/dwds/src/injected/client.js:1223:18)

Expected behavior

The web app should not crash at this point. The firebase_analytics plugin shouldn't access the firebase instance during plugin registration.


Flutter doctor

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel master, 1.24.0-2.0.pre.86, on Microsoft Windows [Version 10.0.18362.295], locale de-DE) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Chrome - develop for the web [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 4.0) [!] Android Studio (version 4.1.0) X Unable to find bundled Java version. [√] VS Code (version 1.50.1) [√] Connected device (3 available) ! Doctor found issues in 2 categories. ```

Flutter dependencies

Click To Expand ``` dependencies: - amplitude_flutter 2.2.1 [flutter] - badges 1.1.1 [flutter] - bloc 6.0.3 [meta] - cached_network_image 2.3.1 [flutter flutter_cache_manager octo_image] - connectivity 0.4.9+5 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - contacts_service 0.3.10 [flutter collection quiver] - country_pickers 1.1.0 [flutter] - cupertino_icons 0.1.3 - decimal 0.3.5 [rational] - device_info 0.4.2+7 [flutter device_info_platform_interface] - equatable 1.2.5 [collection meta] - f_logs 1.2.2 [flutter sembast path_provider intl permission_handler xxtea meta path stack_trace] - file_picker 1.12.0 [flutter flutter_plugin_android_lifecycle file_picker_platform_interface] - file_picker_platform_interface 1.2.0 [flutter plugin_platform_interface] - file_picker_web 1.0.1+1 [file_picker_platform_interface flutter flutter_web_plugins] - firebase_analytics 6.0.2 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_core 0.5.0+1 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_crashlytics 0.2.1+1 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface] - firebase_messaging 7.0.2 [meta flutter firebase_core] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_apns 1.3.1 [flutter firebase_messaging] - flutter_bloc 6.0.5 [flutter bloc provider] - flutter_branch_sdk 1.1.0 [flutter] - flutter_cache_manager 1.4.1 [flutter path_provider uuid http path sqflite pedantic clock file rxdart] - flutter_cupertino_localizations 1.0.1 [flutter flutter_localizations] - flutter_email_sender 2.2.2 [flutter] - flutter_image_compress 0.6.8 [flutter] - flutter_linkify 3.1.3 [flutter linkify] - flutter_local_notifications 1.4.4+4 [flutter platform flutter_local_notifications_platform_interface] - flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math] - flutter_ringtone_player 2.0.0 [flutter] - flutter_sms 1.1.0 [flutter] - flutter_speed_dial 1.2.5 [flutter] - flutter_styled_toast 1.4.0+1 [flutter flutter_localizations] - flutter_svg 0.18.1 [path_drawing xml vector_math meta flutter] - flutter_verification_code_input 0.1.2 [flutter] - get_it 4.0.4 [async meta] - google_fonts 0.3.10 [flutter http path_provider crypto] - hex 0.1.2 - image_picker 0.6.5+2 [flutter flutter_plugin_android_lifecycle] - intl 0.16.1 [path] - json_annotation 3.0.1 - logger 0.8.3 [io] - logging 0.11.4 - material_design_icons_flutter 4.0.5555 [flutter] - matrix_dart_sdk 0.0.1 [flutter chopper json_annotation uuid jaguar_orm mime_type path_provider logger image universal_platform] - mime_type 0.2.7 - oauth2 1.6.1 [http http_parser crypto] - open_file 3.0.1 [flutter ffi] - package_info 0.4.3 [flutter] - path_provider 1.6.14 [flutter path_provider_platform_interface path_provider_macos path_provider_linux] - permission_handler 4.4.0+hotfix.4 [flutter meta permission_handler_platform_interface] - photo_view 0.10.2 [flutter] - preferences 5.2.1 [flutter shared_preferences] - quiver 2.1.3 [matcher meta] - random_color 1.0.5 [flutter] - share 0.6.5 [meta mime flutter] - shared_preferences 0.5.7+2 [meta flutter shared_preferences_platform_interface shared_preferences_macos shared_preferences_web] - simple_animations 1.3.12 [flutter] - sqflite 1.3.1+1 [flutter sqflite_common path] - universal_platform 0.1.3 - url_launcher 5.5.3 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos] - uuid 2.2.2 [crypto convert] - vibration 1.4.0 [flutter] dev dependencies: - build_runner 1.9.0 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - effective_dart 1.2.4 - flutter_launcher_icons 0.7.5 [image args yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_cha nnel string_scanner term_glyph typed_data] - jaguar_orm_gen 2.2.30 [jaguar_query jaguar_orm analyzer build logging source_gen meta] - jaguar_query_sqflite 2.2.11 [flutter sqflite jaguar_query] - json_serializable 3.2.3 [analyzer build build_config json_annotation meta path source_gen] transitive dependencies: - analyzer 0.38.5 [args charcode collection convert crypto front_end glob html kernel meta package_config path pub_semver source_span watcher yaml] - archive 2.0.13 [crypto args path] - args 1.6.0 - async 2.5.0-nullsafety.1 [collection] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - build 1.2.2 [analyzer async convert crypto logging meta path glob] - build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml] - build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 1.2.1 [analyzer build crypto graphs logging package_resolver path yaml] - build_runner_core 5.1.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timin g watcher yaml] - built_collection 4.3.2 [collection quiver] - built_value 7.1.0 [built_collection collection fixnum quiver] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - checked_yaml 1.0.2 [json_annotation source_span yaml] - chopper 3.0.3 [http meta logging] - clock 1.1.0-nullsafety.1 - code_builder 3.4.1 [built_collection built_value collection matcher meta] - collection 1.15.0-nullsafety.3 - connectivity_for_web 0.3.1+2 [connectivity_platform_interface flutter_web_plugins flutter] - connectivity_macos 0.1.0+4 [flutter] - connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface] - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - csslib 0.16.2 [source_span] - dart_style 1.3.3 [analyzer args path source_span] - device_info_platform_interface 1.0.1 [flutter meta plugin_platform_interface] - fake_async 1.2.0-nullsafety.1 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase 7.3.0 [http http_parser js] - firebase_analytics_platform_interface 1.0.3 [flutter meta] - firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta] - firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_crashlytics_platform_interface 1.1.1 [flutter meta collection firebase_core plugin_platform_interface] - fixnum 0.10.11 - flutter_blurhash 0.5.0 [flutter meta] - flutter_local_notifications_platform_interface 1.0.1 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 1.0.8 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - front_end 0.1.27 [kernel package_config meta] - glob 1.2.0 [async collection node_io path pedantic string_scanner] - graphs 0.2.0 - html 0.14.0+3 [csslib source_span] - http 0.12.2 [http_parser path pedantic] - http_multi_server 2.2.0 [async] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image 2.1.14 [archive xml] - io 0.3.4 [charcode meta path string_scanner] - jaguar_orm 2.2.7 [jaguar_query quiver path meta] - jaguar_query 2.2.9 [meta] - js 0.6.3-nullsafety.1 - kernel 0.3.27 [args meta] - linkify 2.1.0 - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.4 - mime 0.9.7 - nested 0.0.4 [flutter] - node_interop 1.1.1 [js] - node_io 1.1.1 [node_interop path] - octo_image 0.2.1 [flutter flutter_blurhash] - package_config 1.9.3 [path charcode] - package_resolver 1.0.10 [collection http package_config path] - path 1.8.0-nullsafety.1 - path_drawing 0.4.1+1 [vector_math meta path_parsing flutter] - path_parsing 0.1.4 [vector_math meta] - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+3 [flutter] - path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface] - pedantic 1.9.0 - permission_handler_platform_interface 1.0.0 [flutter meta plugin_platform_interface] - petitparser 3.0.4 [meta] - platform 2.2.1 - platform_detect 1.4.0 [meta pub_semver] - plugin_platform_interface 1.0.2 [meta] - pool 1.4.0 [async stack_trace] - process 3.0.13 [file intl meta path platform] - provider 4.3.2+2 [flutter nested collection] - pub_semver 1.4.4 [collection] - pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml] - rational 0.3.8 - rxdart 0.23.1 - sembast 2.4.7+6 [meta path synchronized] - shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 1.0.4 [meta flutter] - shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - shelf 0.7.9 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel] - sky_engine 0.0.99 - source_gen 0.9.4+6 [analyzer async build dart_style glob meta path pedantic source_span] - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - sqflite_common 1.0.2+1 [synchronized path meta] - stack_trace 1.10.0-nullsafety.4 [path] - stream_channel 2.1.0-nullsafety.1 [async] - stream_transform 1.2.0 - string_scanner 1.1.0-nullsafety.1 [charcode source_span] - synchronized 2.2.0+2 - term_glyph 1.2.0-nullsafety.1 - test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - timing 0.1.1+2 [json_annotation] - typed_data 1.3.0-nullsafety.3 [collection] - url_launcher_linux 0.0.1+1 [flutter] - url_launcher_macos 0.0.1+7 [flutter] - url_launcher_platform_interface 1.0.8 [flutter meta plugin_platform_interface] - url_launcher_web 0.1.3+2 [url_launcher_platform_interface platform_detect flutter flutter_web_plugins meta] - vector_math 2.1.0-nullsafety.3 - watcher 0.9.7+15 [async path pedantic] - web_socket_channel 1.1.0 [async crypto stream_channel] - xdg_directories 0.1.0 [path process flutter] - xml 4.2.0 [collection convert meta petitparser] - xxtea 2.0.3 - yaml 2.2.1 [charcode collection string_scanner source_span] ```

TahaTesser commented 3 years ago
logs ```bash tahatesser@Tahas-MacBook-Pro master_flutter % flutterm run -d chrome Downloading Web SDK... 7.9s Running "flutter pub get" in master_flutter... 554ms Launching lib/main.dart on Chrome in debug mode... Syncing files to device Chrome... 16.0s Debug service listening on ws://127.0.0.1:63441/EYxShasOVoA= Warning: Flutter's support for web development is not stable yet and hasn't been thoroughly tested in production environments. For more information see https://flutter.dev/web 🔥 To hot restart changes while running, press "r" or "R". For a more detailed help message, press "h". To quit, press "q". the Dart compiler exited unexpectedly. tahatesser@Tahas-MacBook-Pro master_flutter % flutterm run -d chrome Running "flutter pub get" in master_flutter... 547ms Launching lib/main.dart on Chrome in debug mode... Syncing files to device Chrome... 8.8s Debug service listening on ws://127.0.0.1:63565/x0QNt5YIKKk= Warning: Flutter's support for web development is not stable yet and hasn't been thoroughly tested in production environments. For more information see https://flutter.dev/web 🔥 To hot restart changes while running, press "r" or "R". For a more detailed help message, press "h". To quit, press "q". FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). at f (https://www.gstatic.com/firebasejs/7.19.1/firebase-app.js:1:16863) at Object.n [as analytics] (https://www.gstatic.com/firebasejs/7.19.1/firebase-app.js:1:17116) at Object.analytics$ [as analytics] (http://localhost:63536/packages/firebase/src/top_level.dart.lib.js:110:102) at new firebase_analytics_web.FirebaseAnalyticsWeb.new (http://localhost:63536/packages/firebase_analytics_web/firebase_analytics_web.dart.lib.js:56:64) at Function.registerWith (http://localhost:63536/packages/firebase_analytics_web/firebase_analytics_web.dart.lib.js:19:82) at Object.registerPlugins (http://localhost:63536/packages/master_flutter/generated_plugin_registrant.dart.lib.js:13:49) at main (http://localhost:63536/web_entrypoint.dart.lib.js:29:35) at main.next () at runBody (http://localhost:63536/dart_sdk.js:37922:34) at Object._async [as async] (http://localhost:63536/dart_sdk.js:37953:7) at main$ (http://localhost:63536/web_entrypoint.dart.lib.js:28:18) at http://localhost:63536/main_module.bootstrap.js:20:10 at Array.forEach () at window.$dartRunMain (http://localhost:63536/main_module.bootstrap.js:19:32) at :1:8 at Object.runMain (http://localhost:63536/dwds/src/injected/client.js:8764:21) at http://localhost:63536/dwds/src/injected/client.js:22538:19 at _wrapJsFunctionForAsync_closure.$protected (http://localhost:63536/dwds/src/injected/client.js:3793:15) at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:63536/dwds/src/injected/client.js:11010:12) at Object._asyncStartSync (http://localhost:63536/dwds/src/injected/client.js:3757:20) at main__closure1.$call$body$main__closure (http://localhost:63536/dwds/src/injected/client.js:22550:16) at main__closure1.call$1 (http://localhost:63536/dwds/src/injected/client.js:22477:19) at StaticClosure._rootRunUnary [as call$2$5] (http://localhost:63536/dwds/src/injected/client.js:4124:16) at _CustomZone.runUnary$2$2 (http://localhost:63536/dwds/src/injected/client.js:12315:39) at _CustomZone.runUnaryGuarded$1$2 (http://localhost:63536/dwds/src/injected/client.js:12247:14) at _ControllerSubscription._sendData$1 (http://localhost:63536/dwds/src/injected/client.js:11798:19) at _DelayedData.perform$1 (http://localhost:63536/dwds/src/injected/client.js:11950:59) at _PendingEvents_schedule_closure.call$0 (http://localhost:63536/dwds/src/injected/client.js:11999:14) at Object._microtaskLoop (http://localhost:63536/dwds/src/injected/client.js:3960:24) at StaticClosure._startMicrotaskLoop (http://localhost:63536/dwds/src/injected/client.js:3966:11) at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1 (http://localhost:63536/dwds/src/injected/client.js:10879:9) at invokeClosure (http://localhost:63536/dwds/src/injected/client.js:1204:26) at MutationObserver. (http://localhost:63536/dwds/src/injected/client.js:1223:18) ```
flutter doctor -v ```bash [✓] Flutter (Channel master, 1.24.0-4.0.pre.81, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-GB) • Flutter version 1.24.0-4.0.pre.81 at /Users/tahatesser/Code/flutter_master • Framework revision 05ab0eba19 (10 hours ago), 2020-10-26 19:22:25 -0700 • Engine revision 1857470267 • Dart version 2.11.0 (build 2.11.0-260.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/tahatesser/Code/sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = /Users/tahatesser/Code/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.1, Build version 12A7403 • CocoaPods version 1.10.0.rc.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • 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 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.50.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.15.1 [✓] Connected device (4 available) • iPhone 12 (mobile) • BAFAB765-173F-4B78-93AC-F6FB6E6783C3 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.7 19H2 darwin-x64 • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 86.0.4240.111 • No issues found! ```
markusaksli-nc commented 3 years ago

The issue isn't any of these plugins in particular, firebase_core 1.0.0 itself exhibits the same behavior all on its own.

Trace ```console FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). at Object.f [as app] (https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js:1:17054) at Object.app$ [as app] (http://localhost:60661/packages/firebase_core_web/src/interop/core.dart.lib.js:42:101) at initializeApp (http://localhost:60661/packages/firebase_core_web/firebase_core_web.dart.lib.js:100:25) at initializeApp.next () at runBody (http://localhost:60661/dart_sdk.js:39211:34) at Object._async [as async] (http://localhost:60661/dart_sdk.js:39242:7) at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:60661/packages/firebase_core_web/firebase_core_web.dart.lib.js:93:20) at initializeApp (http://localhost:60661/packages/firebase_core/firebase_core.dart.lib.js:117:59) at initializeApp.next () at runBody (http://localhost:60661/dart_sdk.js:39211:34) at Object._async [as async] (http://localhost:60661/dart_sdk.js:39242:7) at Function.initializeApp (http://localhost:60661/packages/firebase_core/firebase_core.dart.lib.js:116:20) at main$ (http://localhost:60661/packages/triage/main.dart.lib.js:251:36) at main$.next () at runBody (http://localhost:60661/dart_sdk.js:39211:34) at Object._async [as async] (http://localhost:60661/dart_sdk.js:39242:7) at main$ (http://localhost:60661/packages/triage/main.dart.lib.js:249:18) at main (http://localhost:60661/web_entrypoint.dart.lib.js:51:29) at main.next () at http://localhost:60661/dart_sdk.js:39191:33 at _RootZone.runUnary (http://localhost:60661/dart_sdk.js:39048:58) at _FutureListener.thenAwait.handleValue (http://localhost:60661/dart_sdk.js:34034:29) at handleValueCallback (http://localhost:60661/dart_sdk.js:34594:49) at Function._propagateToListeners (http://localhost:60661/dart_sdk.js:34632:17) at _Future.new.[_completeWithValue] (http://localhost:60661/dart_sdk.js:34474:23) at http://localhost:60661/dart_sdk.js:33685:46 at _RootZone.runUnary (http://localhost:60661/dart_sdk.js:39048:58) at _FutureListener.then.handleValue (http://localhost:60661/dart_sdk.js:34034:29) at handleValueCallback (http://localhost:60661/dart_sdk.js:34594:49) at Function._propagateToListeners (http://localhost:60661/dart_sdk.js:34632:17) at _Future.new.[_completeWithValue] (http://localhost:60661/dart_sdk.js:34474:23) at async._AsyncCallbackEntry.new.callback (http://localhost:60661/dart_sdk.js:34497:35) at Object._microtaskLoop (http://localhost:60661/dart_sdk.js:39335:13) at _startMicrotaskLoop (http://localhost:60661/dart_sdk.js:39341:13) at http://localhost:60661/dart_sdk.js:34848:9 ```

That being said I'm not sure how the firebase js interop works so I don't know if this is even "fixable" or a valid issue in the first place.

gibahjoe commented 3 years ago

Are there any workarounds for this right now? I can't build because the plugin registers it self and I only need it on mobile, not the web.

@markusaksli-nc, I believe it is an issue because it causes web apps to stop loading when it crashes

markusaksli-nc commented 3 years ago

I'm not aware of a workaround, no. You could consider adding the firebase config in index.html as a "workaround" but that is just how the package works. Though not being able to opt-out of this setup if you don't need it is also what the issue is about.

Nico04 commented 3 years ago

I have the same issue, I don't need Firebase components on the web version of my app, but it seems we cannot opt-out for now :( Same issue here : https://github.com/FirebaseExtended/flutterfire/issues/4837

Ehesp commented 3 years ago

My thoughts on this:

I'm not sure why core is throwing that error when used on it's own @markusaksli-nc - are you literally just importing it but not touching the API?

Taking analytics as an example (one we haven't fully reworked), the registerWith call creates a new FirebaseAnalyticsWeb instance which attempts to create the Analytics instance (hence this error):

  FirebaseAnalyticsWeb({@visibleForTesting firebase.Analytics? analytics})
      : _analytics = analytics ?? firebase.analytics();

  final firebase.Analytics _analytics;

  static void registerWith(Registrar registrar) {
    FirebaseAnalyticsPlatform.instance = FirebaseAnalyticsWeb();
  }

  @override
  Future<void> logEvent({
    required String name,
    Map<String, Object?>? parameters,
  }) async {
    _analytics.logEvent(name, parameters ?? {});
  }

What we could do (not tested), is something like this instead:

  /// A constructor that allows tests to override the firebase.Analytics object.
  FirebaseAnalyticsWeb({@visibleForTesting firebase.Analytics? analytics})
      : _delegate = analytics;

  // Nullable delegate
  final firebase.Analytics? _delegate;

  /// Called by PluginRegistry to register this plugin for Flutter Web
  static void registerWith(Registrar registrar) {
    FirebaseAnalyticsPlatform.instance = FirebaseAnalyticsWeb();
  }

  // Create the instance on demand
  firebase.Analytics get delegate {
    return _delegate ??= firebase.analytics();
  }

    @override
  Future<void> logEvent({
    required String name,
    Map<String, Object?>? parameters,
  }) async {
    delegate.logEvent(name, parameters ?? {});
  }

Would need to test this out, and also check whether it's possible on other plugins with multiple apps.

Andranjo97 commented 3 years ago

Any update on this? I experienced this issue when launching the app in Safari

BrunoGalv commented 3 years ago

Same error here, on analytics and firestore.

If I comment registerWith method it works. https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_analytics/firebase_analytics_web/lib/firebase_analytics_web.dart

/// Called by PluginRegistry to register this plugin for Flutter Web
  static void registerWith(Registrar registrar) {
    //FirebaseAnalyticsPlatform.instance = FirebaseAnalyticsWeb();
  }

Same in cloud_firestore_web

/// Called by PluginRegistry to register this plugin for Flutter Web
  static void registerWith(Registrar registrar) {
    // FirebaseFirestorePlatform.instance = FirebaseFirestoreWeb();
  }
Salakar commented 2 years ago

Resolved in latest releases; https://github.com/FirebaseExtended/flutterfire/blob/master/CHANGELOG.md#2021-11-06