Closed rydan closed 3 years ago
Hi @rydan I'm not seeing this with
firebase_core: ^0.7.0
firebase_messaging: ^8.0.0-dev.14
http: ^0.12.2
Is some part of your code specifically causing this or is it just on startup even when you remove the firebase messaging related code?
Keep in mind that web support is still unofficial for now so errors are to be expected on web if you try to use it https://firebase.flutter.dev/. Thank you
Yuup. Just having it in the pubspec.yaml file seems to be enough. With all messaging code commented out, it still throws the exception. With the "firebase_messaging: ^8.0.0-dev.14" pubspec-line commented out as well, the app works.
Strange, like I said I'm not seeing this.
If you just flutter create
a fresh project and only add the dependency it does this as well?
@markusaksli-nc I am also seeing this problem after updating to firebase_messaging: ^8.0.0-dev.14
. I just tested with fresh project and only this dependency and am getting a very similar error ("messaging" instead of "isSupported"), but I do get the "isSupported" error on my actual project:
TypeError: Cannot read property 'messaging' of undefined
at new firebase_messaging_web.FirebaseMessagingWeb.new
(http://localhost:5000/packages/firebase_messaging_web/firebase_messaging_web.dart.lib.js:133:41)
at Function.registerWith
(http://localhost:5000/packages/firebase_messaging_web/firebase_messaging_web.dart.lib.js:27:73)
at Object.registerPlugins (http://localhost:5000/packages/tmp/generated_plugin_registrant.dart.lib.js:13:49)
at main (http://localhost:5000/web_entrypoint.dart.lib.js:30:35)
at main.next (<anonymous>)
at runBody (http://localhost:5000/dart_sdk.js:38027:34)
at Object._async [as async] (http://localhost:5000/dart_sdk.js:38058:7)
at main$ (http://localhost:5000/web_entrypoint.dart.lib.js:29:18)
at http://localhost:5000/main_module.bootstrap.js:19:10
at Array.forEach (<anonymous>)
at window.$dartRunMain (http://localhost:5000/main_module.bootstrap.js:18:32)
at <anonymous>:1:8
at Object.runMain (http://localhost:5000/dwds/src/injected/client.js:8656:21)
at http://localhost:5000/dwds/src/injected/client.js:22068:19
at _wrapJsFunctionForAsync_closure.$protected (http://localhost:5000/dwds/src/injected/client.js:3830:15)
at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:5000/dwds/src/injected/client.js:10905:12)
at Object._asyncStartSync (http://localhost:5000/dwds/src/injected/client.js:3794:20)
at main__closure1.$call$body$main__closure (http://localhost:5000/dwds/src/injected/client.js:22080:16)
at main__closure1.call$1 (http://localhost:5000/dwds/src/injected/client.js:22007:19)
at StaticClosure._rootRunUnary [as call$2$5] (http://localhost:5000/dwds/src/injected/client.js:4153:16)
at _CustomZone.runUnary$2$2 (http://localhost:5000/dwds/src/injected/client.js:12136:39)
at _CustomZone.runUnaryGuarded$1$2 (http://localhost:5000/dwds/src/injected/client.js:12068:14)
at _ControllerSubscription._sendData$1 (http://localhost:5000/dwds/src/injected/client.js:11697:19)
at _DelayedData.perform$1 (http://localhost:5000/dwds/src/injected/client.js:11849:59)
at _PendingEvents_schedule_closure.call$0 (http://localhost:5000/dwds/src/injected/client.js:11898:14)
at Object._microtaskLoop (http://localhost:5000/dwds/src/injected/client.js:3990:24)
at StaticClosure._startMicrotaskLoop (http://localhost:5000/dwds/src/injected/client.js:3996:11)
at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1
(http://localhost:5000/dwds/src/injected/client.js:10774:9)
at invokeClosure (http://localhost:5000/dwds/src/injected/client.js:1250:26)
at MutationObserver.<anonymous> (http://localhost:5000/dwds/src/injected/client.js:1269:18)
[✓] Flutter (Channel beta, 1.25.0-8.3.pre, on macOS 11.1 20C69 darwin-x64, locale en-US)
• Flutter version 1.25.0-8.3.pre at /Users/daniel/flutter
• Framework revision 5d36f2e7f5 (3 weeks ago), 2021-01-14 15:57:49 -0800
• Engine revision 7a8f8ca02c
• Dart version 2.12.0 (build 2.12.0-133.7.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/daniel/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• 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-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.0
[✓] 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-6915495)
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.19.0
This is the latest Ive been able to pin my firebase packages to:
firebase_analytics: ^6.3.0
firebase_core: ^0.5.3
firebase_crashlytics: ^0.2.4
firebase_dynamic_links: ^0.6.3
firebase_messaging: ^7.0.3
firebase_remote_config: ^0.4.3
With this configuration, I'm able to run it:
firebase_core: 0.7.0
firebase_messaging: ^8.0.0-dev.14
firebase_dynamic_links: ^0.7.0+1
flutter doctor -v
[✓] Flutter (Channel beta, 1.25.0-8.3.pre, on Linux, locale it_IT.UTF-8)
• Flutter version 1.25.0-8.3.pre at /home/lorenzo/flutter
• Framework revision 5d36f2e7f5 (3 settimane fa), 2021-01-14 15:57:49 -0800
• Engine revision 7a8f8ca02c
• Dart version 2.12.0 (build 2.12.0-133.7.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/lorenzo/Android/Sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /home/lorenzo/Scaricati/uncompressed-sources/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Android Studio (version 4.0)
• Android Studio at /home/lorenzo/Scaricati/uncompressed-sources/android-studio
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] IntelliJ IDEA Ultimate Edition (version 2018.1)
• IntelliJ at /home/lorenzo/Scaricati/uncompressed-sources/idea-IU-181.4668.68
• 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
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88
• No issues found!
But if I switch to dev channel
it gives me the message.
Same here
I'm still not seeing this. Could one of you share your index.html
? (without the sensitive information)
I was facing the same problem and o solved it by decreasing some JS libs
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.22.1/firebase-messaging.js"></script>
FYI the docs still recommend you use 7.20.0
for everything since that's what we have tested against.
I have the same issue. The problem occurs if you don't call "firebase.initializeApp" in the index.html and don't include the "firebase-messaging.js" script tag. If I add the script tag, but don't initialize the firebase app in the index.html, I get the "No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()" error. I think, this is a similar problem as these issues:
The generated plugin registrant calls "FirebaseMessagingWeb.registerWith(registrar)", which tries to access the firebase app instance internally. This apparently doesn't work with the approach of initializing the firebase app in the Dart code only. From my point of view, the FirebaseMessagingWeb class shouldn't rely on a firebase app instance in the constructor.
@rydan Need to add the following to your index.html
@rydan Need to add the following to your index.html
As I mentioned before, the actual problem is in the Dart code and not in the JavaScript code. The method "FirebaseMessagingWeb.registerWith(registrar)" relies on an already initialized firebase app. Unfortunately, this registerWith method is called before the main app is initialized, which internally calls the "Firebase.initializeApp" method.
Therefore, the only possibility to make this work at the moment is to initialize the firebase app in the index.html. But then you have to call the firebase.initializeApp method redundantly in two places (actually the service worker is a third place, but I understand that this can't be solved differently at the moment).
This problem occurs when you haven't included the messaging script in your index.html
file and is documented here
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-messaging.js"></script>
You're right. The script tag for "firebase-messaging.js" solves the initally described error "TypeError: Cannot read property 'isSupported' of undefined", but if the firebase app is not initialized in the index.html, the error "No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()" occurs. This means, one can't initialize the firebase app in the Dart code only and has to perform the initialization in the index.html, which leads to some unnecessary redundancy.
Should we create a separate issue for this topics?
is there a way to disable firebase_messaging for the web only? even if I avoid initialization this error seems to show on firebase_messaging 9.0.0
I think, for now the only possibility to make this work is to call the firebase.initializeApp method in the Javascript code in the index.html. You can copy the necessary code from the web app settings in the firebase console. If you don't have created a web app on the console, create it first.
is there a way to disable firebase_messaging for the web only? even if I avoid initialization this error seems to show on
firebase_messaging 9.0.0
@dvaldivia yes you can, Here is an example on how to: https://github.com/Bdaya-Dev/fcm_handler/blob/master/lib/bdaya_fcm_handler.dart#L72
Hello! I had the same problem: "TypeError: Cannot read property 'isSupported' of undefined..."
So, to resolve, you must add to index.html both lines:
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-messaging.js"></script>
firebase-app.js - to dependency firebase_core and firebase-messaging.js - to dependency firebase_messaging
This info in docs for firebase_messaging: https://firebase.flutter.dev/docs/messaging/usage
Bug report
After upgrading FlutterFire to core 0.7.0 (in turn requiring messaging 8.0.0-dev.14), starting the webapp locally with "flutter run -d chrome" gives the following exception:
Reverting back to earlier FlutterFire, and the exception is gone.
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
[✓] Flutter (Channel beta, 1.25.0-8.3.pre, on Mac OS X 10.14.6 18G7016 darwin-x64, locale en-SE) • Flutter version 1.25.0-8.3.pre at /Users/rydan/Development/flutter • Framework revision 5d36f2e7f5 (13 days ago), 2021-01-14 15:57:49 -0800 • Engine revision 7a8f8ca02c • Dart version 2.12.0 (build 2.12.0-133.7.beta) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/rydan/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • 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 installation is incomplete; a full installation is necessary for iOS development. Download at: https://developer.apple.com/xcode/download/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 49.0.2 • Dart plugin version 193.7547 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] IntelliJ IDEA Ultimate Edition (version 2020.2.3) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 52.0.2 • Dart plugin version 202.8070 [✓] VS Code (version 1.52.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension can be installed from: 🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [✓] Connected device (1 available) • Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.96 ! Device emulator-5562 is offline.Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
Dart SDK 2.12.0-133.7.beta Flutter SDK 1.25.0-8.3.pre dev-proj 1.0.6+21 dependencies: - cloud_firestore 0.16.0 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - cupertino_icons 0.1.3 - firebase_analytics 7.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_auth 0.20.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_messaging 8.0.0-dev.14 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web] - firebase_storage 7.0.0 [flutter firebase_core firebase_core_platform_interface firebase_storage_web firebase_storage_platform_interface quiver] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_cached_pdfview 0.2.9 [flutter flutter_pdfview flutter_cache_manager path_provider path] - flutter_svg 0.18.1 [path_drawing xml vector_math meta flutter] - intl 0.16.1 [path] - provider 4.3.3 [collection flutter nested] - rxdart 0.24.1 - url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows] - vibration 1.7.3 [flutter vibration_web] dev dependencies: - 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_channel string_scanner term_glyph typed_data] transitive dependencies: - archive 2.0.13 [crypto args path] - args 1.6.0 - async 2.5.0-nullsafety.3 [collection] - boolean_selector 2.1.0-nullsafety.3 [source_span string_scanner] - characters 1.1.0-nullsafety.5 - charcode 1.2.0-nullsafety.3 - clock 1.1.0-nullsafety.3 - cloud_firestore_platform_interface 3.0.1 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.3.0+1 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js] - collection 1.15.0-nullsafety.5 - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - fake_async 1.2.0-nullsafety.3 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase 7.3.3 [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_auth_platform_interface 3.0.1 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.2+6 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js] - firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_messaging_platform_interface 1.0.0-dev.10 [flutter meta firebase_core plugin_platform_interface] - firebase_messaging_web 0.1.0-dev.5 [flutter flutter_web_plugins meta firebase_core firebase_core_web firebase_messaging_platform_interface js service_worker] - firebase_storage_platform_interface 1.0.4 [flutter meta collection firebase_core plugin_platform_interface] - firebase_storage_web 0.1.1+3 [async crypto firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_cache_manager 2.1.1 [flutter path_provider uuid http path sqflite pedantic clock file rxdart image] - flutter_pdfview 1.0.4 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - http 0.12.2 [http_parser path pedantic] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image 2.1.19 [archive xml meta] - js 0.6.3-nullsafety.3 - matcher 0.12.10-nullsafety.3 [stack_trace] - meta 1.3.0-nullsafety.6 - nested 0.0.4 [flutter] - path 1.8.0-nullsafety.3 - path_drawing 0.4.1+1 [vector_math meta path_parsing flutter] - path_parsing 0.1.4 [vector_math meta] - path_provider 1.6.27 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+8 [flutter] - path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface] - path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.9.2 [meta] - petitparser 3.1.0 [meta] - platform 2.2.1 - plugin_platform_interface 1.0.3 [meta] - process 3.0.13 [file intl meta path platform] - quiver 2.1.5 [matcher meta] - service_worker 0.2.4 [js] - sky_engine 0.0.99 - source_span 1.8.0-nullsafety.4 [charcode collection path term_glyph] - sqflite 1.3.2+2 [flutter sqflite_common path] - sqflite_common 1.0.3 [synchronized path meta] - stack_trace 1.10.0-nullsafety.6 [path] - stream_channel 2.1.0-nullsafety.3 [async] - string_scanner 1.1.0-nullsafety.3 [charcode source_span] - synchronized 2.2.0+2 - term_glyph 1.2.0-nullsafety.3 - test_api 0.2.19-nullsafety.6 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0-nullsafety.5 [collection] - url_launcher_linux 0.0.1+4 [flutter] - url_launcher_macos 0.0.1+9 [flutter] - url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface] - url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta] - url_launcher_windows 0.0.1+3 [flutter] - uuid 2.2.2 [crypto convert] - vector_math 2.1.0-nullsafety.5 - vibration_web 1.6.2 [flutter flutter_web_plugins] - win32 1.7.4 [ffi] - xdg_directories 0.1.2 [meta path process] - xml 4.5.1 [collection convert meta petitparser] - yaml 2.2.1 [charcode collection string_scanner source_span]