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.71k stars 3.97k forks source link

firebase_core: Firebase won't initialize app on Flutter Web! #12959

Closed adifyr closed 4 months ago

adifyr commented 4 months ago

Is there an existing issue for this?

Which plugins are affected?

Core

Which platforms are affected?

Web

Description

Firebase won't initialize on my Flutter Web App. My VSCode debugger stops and finds an exception on this line:

await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

I'm getting the following errors in my console:

dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3  throw_
packages/flutter/src/services/platform_channel.dart 332:7                    _invokeMethod
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50           <fn>
dart-sdk/lib/async/zone.dart 1661:54                                         runUnary
dart-sdk/lib/async/future_impl.dart 163:18                                   handleValue
dart-sdk/lib/async/future_impl.dart 847:44                                   handleValueCallback
dart-sdk/lib/async/future_impl.dart 876:13                                   _propagateToListeners

I have absolutely no idea what these errors are or what they mean! My project was working yesterday, with the same code, but isn't today. Here's the entire main() function:

void main() async {
  final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
  await Firebase.initializeApp(options: DefaultFirebaseOptions.web);
  usePathUrlStrategy();
  Hive.defaultDirectory = (await getApplicationDocumentsDirectory()).path;
  runApp(const MemorioSite());
}

Things I've already tried.

  1. I cleared the local project cache with flutter clean and did flutter pub get all over again.
  2. I cleared the global cache with flutter pub cache clean.
  3. I checked my firebase_options.dart to see if they reflected the correct keys.
  4. I even created an entirely new project! Configured firebase on that project and STILL GET THE SAME ERROR.

At this point, I have no idea what's wrong or what to do. Please Help! Even figuring out what the error logs are would be a big help!

Reproducing the issue

I have the following main method in my main.dart file:

void main() async {
  final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
  await Firebase.initializeApp(options: DefaultFirebaseOptions.web); // ERROR HAPPENS HERE.
  usePathUrlStrategy();
  Hive.defaultDirectory = (await getApplicationDocumentsDirectory()).path;
  runApp(const MemorioSite());
}

Firebase Core version

3.1.0

Flutter Version

3.22.2

Relevant Log Output

Error
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3  throw_
packages/flutter/src/services/platform_channel.dart 332:7                    _invokeMethod
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50           <fn>
dart-sdk/lib/async/zone.dart 1661:54                                         runUnary
dart-sdk/lib/async/future_impl.dart 163:18                                   handleValue
dart-sdk/lib/async/future_impl.dart 847:44                                   handleValueCallback
dart-sdk/lib/async/future_impl.dart 876:13                                   _propagateToListeners

Flutter dependencies

Expand Flutter dependencies snippet
```yaml Dart SDK 3.4.3 Flutter SDK 3.22.2 site 1.0.0+1 dependencies: - audioplayers 6.0.0 [audioplayers_android audioplayers_darwin audioplayers_linux audioplayers_platform_interface audioplayers_web audioplayers_windows file flutter http meta path_provider synchronized uuid] - cloud_firestore 5.0.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - collection 1.18.0 - firebase_core 3.1.0 [firebase_core_platform_interface firebase_core_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_animate 4.5.0 [flutter flutter_shaders] - flutter_native_splash 2.4.0 [args flutter flutter_web_plugins html image meta path universal_io xml yaml ansicolor] - flutter_riverpod 2.5.1 [collection flutter meta riverpod state_notifier] - flutter_svg 2.0.10+1 [flutter http vector_graphics vector_graphics_codec vector_graphics_compiler] - google_fonts 6.2.1 [flutter http path_provider crypto] - hive 4.0.0-dev.2 [isar meta] - isar_flutter_libs 4.0.0-dev.14 [flutter isar] - jiffy 6.3.1 [intl] - material_symbols_icons 4.2762.0 [flutter] - path_provider 2.1.3 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - simple_icons 10.1.3 [flutter] - url_launcher 6.3.0 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] dev dependencies: - flutter_lints 3.0.2 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service] transitive dependencies: - _fe_analyzer_shared 67.0.0 [meta] - _flutterfire_internals 1.3.37 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 6.4.1 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - ansicolor 2.0.2 - archive 3.6.1 [crypto path] - args 2.5.0 - async 2.11.0 [collection meta] - audioplayers_android 5.0.0 [audioplayers_platform_interface flutter] - audioplayers_darwin 6.0.0 [audioplayers_platform_interface flutter] - audioplayers_linux 4.0.0 [audioplayers_platform_interface flutter] - audioplayers_platform_interface 7.0.0 [collection flutter meta plugin_platform_interface] - audioplayers_web 5.0.0 [audioplayers_platform_interface flutter flutter_web_plugins web] - audioplayers_windows 4.0.0 [audioplayers_platform_interface flutter] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.4.1 [analyzer async convert crypto glob logging meta package_config path] - characters 1.3.0 - clock 1.1.1 - cloud_firestore_platform_interface 6.2.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 4.0.1 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins] - convert 3.1.1 [typed_data] - crypto 3.0.3 [typed_data] - csslib 1.0.0 [source_span] - dart_style 2.3.6 [analyzer args collection path pub_semver source_span] - fake_async 1.3.1 [clock collection] - ffi 2.1.2 - file 7.0.0 [meta path] - firebase_core_platform_interface 5.1.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.17.2 [firebase_core_platform_interface flutter flutter_web_plugins meta web] - fixnum 1.1.0 - flutter_shaders 0.1.2 [flutter vector_math] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math] - glob 2.1.2 [async collection file path string_scanner] - html 0.15.4 [csslib source_span] - http 1.2.1 [async http_parser meta web] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.2.0 [archive meta xml] - intl 0.19.0 [clock meta path] - isar 4.0.0-dev.14 [analyzer build ffi js meta source_gen] - js 0.6.7 [meta] - leak_tracker 10.0.4 [clock collection meta path vm_service] - leak_tracker_flutter_testing 3.0.3 [flutter leak_tracker leak_tracker_testing matcher meta] - leak_tracker_testing 3.0.1 [leak_tracker matcher meta] - lints 3.0.0 - logging 1.2.0 - matcher 0.12.16+1 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.8.0 [collection] - meta 1.12.0 - package_config 2.1.0 [path] - path 1.9.0 - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.2.5 [flutter path_provider_platform_interface] - path_provider_foundation 2.4.0 [flutter path_provider_platform_interface] - path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32] - petitparser 6.0.2 [meta] - platform 3.1.5 - plugin_platform_interface 2.1.8 [meta] - pub_semver 2.1.4 [collection meta] - riverpod 2.5.1 [collection meta stack_trace state_notifier] - sky_engine 0.0.99 - source_gen 1.5.0 [analyzer async build dart_style glob path source_span yaml] - source_span 1.10.0 [collection path term_glyph] - sprintf 7.0.0 - stack_trace 1.11.1 [path] - state_notifier 1.0.0 [meta] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - synchronized 3.1.0+1 - term_glyph 1.2.1 - test_api 0.7.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - typed_data 1.3.2 [collection] - universal_io 2.2.2 [collection meta typed_data] - url_launcher_android 6.3.3 [flutter url_launcher_platform_interface] - url_launcher_ios 6.3.0 [flutter url_launcher_platform_interface] - url_launcher_linux 3.1.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.2.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface] - url_launcher_web 2.3.1 [flutter flutter_web_plugins url_launcher_platform_interface web] - url_launcher_windows 3.1.1 [flutter url_launcher_platform_interface] - uuid 4.4.0 [crypto sprintf meta fixnum] - vector_graphics 1.1.11+1 [flutter http vector_graphics_codec] - vector_graphics_codec 1.1.11+1 - vector_graphics_compiler 1.1.11+1 [args meta path_parsing xml vector_graphics_codec path] - vector_math 2.1.4 - vm_service 14.2.1 - watcher 1.1.0 [async path] - web 0.5.1 - win32 5.5.1 [ffi] - xdg_directories 1.0.4 [meta path] - xml 6.5.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

Additional context and comments

Whenever I try to Hot Restart the Flutter Web App, it tries to open a file called web_entrypoint.dart, which doesn't exist in my project.

TarekkMA commented 4 months ago

Hello @adifyr, Thank you for reporting this issue, can you try to run one of the flutterfire example apps in this repo and see if the same issue also happens?

adifyr commented 4 months ago

Hi. I've learned what caused the error. Firebase does not play well with Hive 4.0.0-dev.2 and Isar-flutter-libs. I believe it's because they both locally save data to the same storage directory and so there's a clash?

Removing Hive resolved the issue for me.

Lyokone commented 4 months ago

Thanks for reporting back, i'll close this since it's not directly caused by FlutterFire.