Flutterfire: [firebase_auth_web] getting "Cannot read property 'app' of undefined" when running app in web

Created on 21 Dec 2019  Â·  14Comments  Â·  Source: FirebaseExtended/flutterfire

Uncaught (in promise) TypeError: Cannot read property 'app' of undefined
    at Object.app$ [as app] (top_level.dart:77)
    at firebase_auth_web.FirebaseAuthWeb.new.[_getAuth] (firebase_auth_web.dart:19)
    at firebase_auth_web.FirebaseAuthWeb.new.getCurrentUser (firebase_auth_web.dart:155)
    at getCurrentUser.next (<anonymous>)
    at runBody (async_patch.dart:86)
    at Object._async [as async] (async_patch.dart:125)
    at firebase_auth_web.FirebaseAuthWeb.new.getCurrentUser (firebase_auth_web.dart:154)
    at firebase_auth.FirebaseAuth.__.currentUser (firebase_auth.dart:316)
    at currentUser.next (<anonymous>)
    at runBody (async_patch.dart:86)
    at Object._async [as async] (async_patch.dart:125)
    at firebase_auth.FirebaseAuth.__.currentUser (firebase_auth.dart:314)
    at auth.Auth.new.isAuth (auth.dart:64)
    at isAuth.next (<anonymous>)
    at runBody (async_patch.dart:86)
    at Object._async [as async] (async_patch.dart:125)
    at auth.Auth.new.isAuth (auth.dart:56)
    at main._MainPageState.new.didChangeDependencies (main.dart:107)
    at framework.StatefulElement.new.[_firstBuild] (framework.dart:4449)
    at framework.StatefulElement.new.mount (framework.dart:4274)
web auth bug

Most helpful comment

Screenshot (123)_LI
Screenshot (124)_LI
Screenshot (125)_LI
Screenshot (128)_LI
follow these steps on fire base
Screenshot (129)_LI


Screenshot (130)_LI

firebase_auth:
firebase_auth_web:

All 14 comments

Hi @alarmatwork
can you please provide your flutter doctor -v
and your flutter run --verbose?
Thank you

encountered the same issue. to get auth to web there are no additional configurations needed?

`✓] Flutter (Channel beta, v1.12.13+hotfix.6, on Linux, locale
en_US.UTF-8)
• Flutter version 1.12.13+hotfix.6 at /home/philipp/Programs/flutter
• Framework revision 18cd7a3601 (13 days ago), 2019-12-11 06:35:39
-0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0

[!] Android toolchain - develop for Android devices (Android SDK version
29.0.2)
• Android SDK at /home/philipp/Android/Sdk
• Android NDK location not configured (optional; useful for native
profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /home/philipp/Programs/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
! Some Android licenses not accepted. To resolve this, run: flutter
doctor --android-licenses

[✓] Chrome - develop for the web
• Chrome at google-chrome

[✓] Android Studio (version 3.5)
• Android Studio at /home/philipp/Programs/android-studio
• Flutter plugin version 41.1.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (2 available)
• Chrome • chrome • web-javascript • Google Chrome
78.0.3904.108
• Web Server • web-server • web-javascript • Flutter Tools
[ +76 ms] executing: [/home/philipp/Programs/flutter/] git -c
log.showSignature=false log -n 1 --pretty=format:%H
[ +118 ms] Exit code 0 from: git -c log.showSignature=false log -n 1
--pretty=format:%H
[ +7 ms] 18cd7a3601bcffb36fdf2f679f763b5e827c2e8e
[ +1 ms] executing: [/home/philipp/Programs/flutter/] git describe
--match v..* --first-parent --long --tags
[ +24 ms] Exit code 0 from: git describe --match v..* --first-parent
--long --tags
[ +2 ms] v1.12.13+hotfix.6-0-g18cd7a360
[ +24 ms] executing: [/home/philipp/Programs/flutter/] git rev-parse
--abbrev-ref --symbolic @{u}
[ +22 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ ] origin/beta
[ ] executing: [/home/philipp/Programs/flutter/] git ls-remote
--get-url origin
[ +22 ms] Exit code 0 from: git ls-remote --get-url origin
[ ] https://github.com/flutter/flutter.git
[ +154 ms] executing: [/home/philipp/Programs/flutter/] git rev-parse
--abbrev-ref HEAD
[ +30 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[ ] beta
[ +488 ms] executing: /home/philipp/Android/Sdk/platform-tools/adb
devices -l
[ +24 ms] Exit code 0 from:
/home/philipp/Android/Sdk/platform-tools/adb devices -l
[ +1 ms] List of devices attached
[ +61 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required,
skipping update.
[ +1 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not
required, skipping update.
[ +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not
required, skipping update.
[ +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required,
skipping update.
[ +59 ms] Artifact Instance of 'WindowsEngineArtifacts' is not
required, skipping update.
[ +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required,
skipping update.
[ +1 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required,
skipping update.
[ +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not
required, skipping update.
[ +2 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not
required, skipping update.
[ +1 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not
required, skipping update.
[ +1 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not
required, skipping update.
[+2201 ms] Found plugin firebase_auth at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_auth-0.15.3/
[ +165 ms] Found plugin firebase_auth_web at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_auth_web-0.1.1+1/
[ +91 ms] Found plugin firebase_core at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_core-0.4.3+1/
[+1211 ms] Found plugin firebase_core_web at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_core_web-0.1.1+1/
[+1682 ms] Found plugin geocoder at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/geocod
er-0.2.1/
[+2044 ms] Found plugin path_provider at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/path_p
rovider-1.5.1/
[ +253 ms] Found plugin sqflite at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/sqflit
e-1.2.0/
[+2447 ms] Found plugin firebase_auth at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_auth-0.15.3/
[ +8 ms] Found plugin firebase_auth_web at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_auth_web-0.1.1+1/
[ +6 ms] Found plugin firebase_core at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_core-0.4.3+1/
[ +9 ms] Found plugin firebase_core_web at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_core_web-0.1.1+1/
[ +31 ms] Found plugin geocoder at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/geocod
er-0.2.1/
[ +30 ms] Found plugin path_provider at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/path_p
rovider-1.5.1/
[ +19 ms] Found plugin sqflite at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/sqflit
e-1.2.0/
[+2842 ms] Generating
/home/philipp/yoga_frontend/android/app/src/main/java/io/flutter/plugins
/GeneratedPluginRegistrant.java
[ +893 ms] Launching lib/main.dart on Chrome in debug mode...
[ +2 ms] Building application for the web...
[+4455 ms] Found plugin firebase_auth at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_auth-0.15.3/
[ +5 ms] Found plugin firebase_auth_web at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_auth_web-0.1.1+1/
[ +4 ms] Found plugin firebase_core at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_core-0.4.3+1/
[ +6 ms] Found plugin firebase_core_web at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/fireba
se_core_web-0.1.1+1/
[ +19 ms] Found plugin geocoder at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/geocod
er-0.2.1/
[ +23 ms] Found plugin path_provider at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/path_p
rovider-1.5.1/
[ +18 ms] Found plugin sqflite at
/home/philipp/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/sqflit
e-1.2.0/
[+62756 ms] Starting daemon...
[ +738 ms] Initializing inputs
[ +77 ms] Reading cached asset graph...
[ +710 ms] Reading cached asset graph completed, took 703ms

[+1067 ms] Checking for updates since last build...
[+3810 ms] Checking for updates since last build completed, took 3.8s

[ +33 ms] Initializing inputs
[ +6 ms] Reading cached asset graph...
[ ] Reading cached asset graph completed, took 703ms
[ ] Checking for updates since last build...
[ ] Checking for updates since last build completed, took 3.8s
[ +540 ms] Serving DevTools at http://127.0.0.1:39933

[+2422 ms] About to build [web]...
[ +12 ms] Running build...
[ +637 ms] Running build completed, took 334ms

[ +3 ms] Caching finalized dependency graph...
[ +118 ms] Caching finalized dependency graph completed, took 482ms

[ +53 ms] Succeeded after 875ms with 0 outputs (0 actions)

[ +38 ms] Building application for the web... (completed in 77.5s)
[ ] Attempting to connect to browser instance..
[+27261 ms] Debug service listening on ws://127.0.0.1:36193/O7mXR0QNgJI=

[ +976 ms] Failed to load asset at path:
packages/build_web_compilers/src/dev_compiler/dart_sdk.js.

                      Status code: 404

                      Headers:
                      {
                  "date": "Tue, 24 Dec 2019 11:53:51 GMT",
                  "content-length": "9",
                  "x-frame-options": "SAMEORIGIN",
                  "content-type": "text/plain; charset=utf-8",
                  "x-xss-protection": "1; mode=block",
                  "x-content-type-options": "nosniff",
                  "server": "dart:io with Shelf",
                  "via": "1.1 shelf_proxy"
                }

                      Content:
                      Not Found}

[ +179 ms] Attempting to connect to browser instance.. (completed in
28.4s)
[ +6 ms] 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
[ +4 ms] 🔥 To hot restart changes while running, press "r". To hot
restart (and
refresh the browser), press "R".
[ +5 ms] For a more detailed help message, press "h". To quit, press
"q".
[ +83 ms] Debug service listening on ws://127.0.0.1:36193/O7mXR0QNgJI=
[+3799 ms] --- Parse json from: assets/texts/texts_landing_page.json
[ +27 ms] --- Parse json from: assets/texts/texts_landing_page.json
[+15837 ms] --- Parse json from:
assets/texts/texts_signup_instructor_page.json
[ +598 ms] --- Parse json from:
assets/texts/texts_signup_instructor_page.json
[+24152 ms] TypeError: Cannot read property 'app' of undefined
[+2327 ms] TypeError: Cannot read property 'app' of undefined
`

check if the app is configured correctly in the web/index.html file. see #a4779ef and here

As pointed out by @senordonfelipe for any supported platform, Firebase app instance needs to authenticate with the matching backend instance. For Android and iOS this is handled for you in the SDK (that's why you need to place google-services.json and GoogleService-Info.plist at the appropriate path) but in order to handle initialization on web, you need to make sure to (indirectly or directly) call initializeApp(configurationOptions) before making any call to Firebase libraries.

On your Firebase console, go to your app settings and down at the bottom look for Firebase SDK snippet.

Select CDN from the options, then copy that code and paste it into your web/index.html file at the end of the body tag

I'm not finding this 'CDN' you speak of. Do you mean this code?:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>stock_stats</title>
</head>
<body>
  <script src="main.dart.js" type="application/javascript"></script>
  <script type="application/javascript">
  var admin = require("firebase-admin");

  var serviceAccount = require("./google-services.json");

  admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://<MY APP ID>.firebaseio.com"
  });
  </script>
</body>
</html>

Screenshot (123)_LI
Screenshot (124)_LI
Screenshot (125)_LI
Screenshot (128)_LI
follow these steps on fire base
Screenshot (129)_LI


Screenshot (130)_LI

firebase_auth:
firebase_auth_web:

@vinayvishnu725 I followed your steps but get an error in the index.html

Uncaught ReferenceError: firebase is not defined
at (index):32

````

  1. // Initialize Firebase
  2. firebase.initializeApp(firebaseConfig);
  3. firebase.analytics();
    ````

@dave-k @Andrious have you used these below below scripts...

And this script is for only firebase email authentication ,, not for Google,Facebook , phone number and other authentication...

Before all these steps you must create an web app on firebase ... not an android or an iOS app...

Yes I followed each of your steps and created an web app on firebase

index.html

image

Here is my pubspec.yaml
Could there be a conflict with the packages or versions that causes the error?

Uncaught ReferenceError: firebase is not defined at (index):32

````
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.13.0+1
provider: ^4.0.3
flutter_spinkit: ^4.1.1+1

firebase_auth: ^0.15.4
firebase_auth_web: ^0.1.2

flutter_launcher_icons: ^0.7.4

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter
# flutter_icons configuration option
flutter_icons:
image_path: "assets/images/icon.png"
android: true
ios: true
````

@dave-k
Screenshot (131)_LI

dont give space in between other dependencies... space alsoo matters in dart... and keep the all versions below the "cupertino_icons" and no need of versions.... give empty versions ... it works....
some changes i made you can check ....

version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_auth:
firebase_auth_web:
cloud_firestore: ^0.13.0+1
provider: ^4.0.3
flutter_spinkit: ^4.1.1+1
flutter_launcher_icons: ^0.7.4

dev_dependencies:
flutter_test:
sdk: flutter
# flutter_icons configuration option
flutter_icons:
image_path: "assets/images/icon.png"
android: true
ios: true

@dave-k @Andrious have you used these below below scripts...

And this script is for only firebase email authentication ,, not for Google,Facebook , phone number and other authentication...

Before all these steps you must create an web app on firebase ... not an android or an iOS app...

and what would you add to enable Google sign in? I've added google_sign_in_web in my pubspec.yaml but still getting the same blank page with a "firebase is not defined" error

@dave-k
<script src="main.dart.js" type="application/javascript"></script> should be the last script before the closing body tag

image

If you are not loading scripts into the HTML file dynamically or marking them as async, the scripts are loaded in order they are entered into the index.html file. For reference

Was this page helpful?
0 / 5 - 0 ratings