Flutter and Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - firebase

I've set up firebase with Flutter for iOS and Android.
When running flutter run I'm getting the error with the following error:
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:50861/packages/firebase_core_web/src/interop/core.dart.lib.js:42:101)
at initializeApp
(http://localhost:50861/packages/firebase_core_web/firebase_core_web.dart.lib.js:101:25)
at initializeApp.next (<anonymous>)
at runBody (http://localhost:50861/dart_sdk.js:39052:34)
at Object._async [as async] (http://localhost:50861/dart_sdk.js:39083:7)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp
(http://localhost:50861/packages/firebase_core_web/firebase_core_web.dart.lib.js:94:20)
at initializeApp (http://localhost:50861/packages/firebase_core/firebase_core.dart.lib.js:117:59)
at initializeApp.next (<anonymous>)
at runBody (http://localhost:50861/dart_sdk.js:39052:34)
at Object._async [as async] (http://localhost:50861/dart_sdk.js:39083:7)
at Function.initializeApp
(http://localhost:50861/packages/firebase_core/firebase_core.dart.lib.js:116:20)
at main$ (http://localhost:50861/packages/scbeta/main.dart.lib.js:477:36)
at main$.next (<anonymous>)
at runBody (http://localhost:50861/dart_sdk.js:39052:34)
at Object._async [as async] (http://localhost:50861/dart_sdk.js:39083:7)
at main$ (http://localhost:50861/packages/scbeta/main.dart.lib.js:475:18)
at main (http://localhost:50861/web_entrypoint.dart.lib.js:49:29)
at main.next (<anonymous>)
at http://localhost:50861/dart_sdk.js:39032:33
at _RootZone.runUnary (http://localhost:50861/dart_sdk.js:38889:58)
at _FutureListener.thenAwait.handleValue (http://localhost:50861/dart_sdk.js:33875:29)
at handleValueCallback (http://localhost:50861/dart_sdk.js:34435:49)
at Function._propagateToListeners (http://localhost:50861/dart_sdk.js:34473:17)
at _Future.new.[_completeWithValue] (http://localhost:50861/dart_sdk.js:34315:23)
at http://localhost:50861/dart_sdk.js:33526:46
at _RootZone.runUnary (http://localhost:50861/dart_sdk.js:38889:58)
at _FutureListener.then.handleValue (http://localhost:50861/dart_sdk.js:33875:29)
at handleValueCallback (http://localhost:50861/dart_sdk.js:34435:49)
at Function._propagateToListeners (http://localhost:50861/dart_sdk.js:34473:17)
at _Future.new.[_completeWithValue] (http://localhost:50861/dart_sdk.js:34315:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:50861/dart_sdk.js:34338:35)
at Object._microtaskLoop (http://localhost:50861/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:50861/dart_sdk.js:39182:13)
at http://localhost:50861/dart_sdk.js:34689:9
The main function in my main.dart looks like this:
Future<void> main() async {
// Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
I haven't made any firebase calls or initialisations anywhere else in the app.
In my pubspec.yaml I only have firebase_core: ^1.0.1 as a dependency
I have looked at several questions on StackOverflow of people who've had similar problems but none of the solutions where of any help to me.

Have you already created firebase app and configure it for your flutter app?

I've solved it.
The problem was, that with Flutter 2 which just came out a few days ago, you have to add web as a platform as well which none of the tutorials or solutions I've seen mentioned. Once I've added Web on firebase and the scripts in flutter it worked just fine.

Related

Error while initializing Firebase in Flutter

My main.dart:
void main() async {
await preinit();
await di<FirebaseAuthService>().useEmulator();
await di<FirebaseFunctionsService>().useEmulator();
await initApp();
}
Part of my FirebaseAuthService:
#singleton
class FirebaseAuthService {
final FirebaseAuth _service;
FirebaseAuthService(FirebaseCoreService firebaseCoreService)
: _service = FirebaseAuth.instanceFor(app: firebaseCoreService.app);
}
Part of my FirebaseFunctionsService:
#injectable
class FirebaseFunctionsService {
final FirebaseFunctions _service;
FirebaseFunctionsService(FirebaseCoreService firebaseCoreService)
: _service = FirebaseFunctions.instanceFor(app: firebaseCoreService.app);
}
My FirebaseCoreService:
#singleton
class FirebaseCoreService {
final FirebaseApp _app;
FirebaseApp get app => _app;
FirebaseCoreService._(this._app);
#factoryMethod
static Future<FirebaseCoreService> create() async {
final app = await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
if (!kIsWeb) {
await FirebaseCrashlytics.instance
.setCrashlyticsCollectionEnabled(!kDebugMode);
}
return FirebaseCoreService._(app);
}
}
At Firebase.initializeApp that is called right after preinit() in main.dart, I get the following error:
"Error: Invalid argument(s): object cannot be a num, string, bool, or null
at Object.throw_ [as throw] (http://localhost:50958/dart_sdk.js:5080:11)
at JsObject.fromBrowserObject (http://localhost:50958/dart_sdk.js:61852:19)
at get [_ignoredServiceScripts] (http://localhost:50958/packages/firebase_core_web/firebase_core_web.dart.lib.js:147:35)
at firebase_core_web.FirebaseCoreWeb.new._initializeCore (http://localhost:50958/packages/firebase_core_web/firebase_core_web.dart.lib.js:182:27)
at _initializeCore.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at [_initializeCore] (http://localhost:50958/packages/firebase_core_web/firebase_core_web.dart.lib.js:177:20)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:50958/packages/firebase_core_web/firebase_core_web.dart.lib.js:199:36)
at initializeApp.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:50958/packages/firebase_core_web/firebase_core_web.dart.lib.js:198:20)
at initializeApp (http://localhost:50958/packages/firebase_core/firebase_core.dart.lib.js:105:59)
at initializeApp.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at Firebase.initializeApp (http://localhost:50958/packages/firebase_core/firebase_core.dart.lib.js:104:20)
at create (http://localhost:50958/packages/wa_flutter_questionnaire/data/firebase/firebase_core_service.dart.lib.js:26:49)
at create.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at FirebaseCoreService.create (http://localhost:50958/packages/wa_flutter_questionnaire/data/firebase/firebase_core_service.dart.lib.js:25:20)
at http://localhost:50958/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1903:130
at get_it_helper.GetItHelper.new.singletonAsync (http://localhost:50958/packages/injectable/src/get_it_helper.dart.lib.js:117:18)
at $36initGetIt (http://localhost:50958/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1903:16)
at $36initGetIt.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at Object.$36initGetIt [as $initGetIt] (http://localhost:50958/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1900:18)
at configureDependencies (http://localhost:50958/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1918:32)
at configureDependencies.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at Object.configureDependencies (http://localhost:50958/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1917:18)
at preinit (http://localhost:50958/packages/wa_flutter_questionnaire/main.dart.lib.js:55:16)
at preinit.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at Object.preinit (http://localhost:50958/packages/wa_flutter_questionnaire/main.dart.lib.js:52:18)
at main$ (http://localhost:50958/packages/wa_flutter_questionnaire/main_local.dart.lib.js:18:18)
at main$.next (<anonymous>)
at runBody (http://localhost:50958/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:50958/dart_sdk.js:40691:7)
at main$ (http://localhost:50958/packages/wa_flutter_questionnaire/main_local.dart.lib.js:17:18)
at http://localhost:50958/web_entrypoint.dart.lib.js:37:33
at Object._checkAndCall (http://localhost:50958/dart_sdk.js:5279:16)
at Object.dcall (http://localhost:50958/dart_sdk.js:5284:17)
at http://localhost:50958/dart_sdk.js:140291:18
at Generator.next (<anonymous>)
at http://localhost:50958/dart_sdk.js:40641:33
at _RootZone.runUnary (http://localhost:50958/dart_sdk.js:40511:59)
at _FutureListener.thenAwait.handleValue (http://localhost:50958/dart_sdk.js:35438:29)
at handleValueCallback (http://localhost:50958/dart_sdk.js:35999:49)
at _Future._propagateToListeners (http://localhost:50958/dart_sdk.js:36037:17)
at [_completeWithValue] (http://localhost:50958/dart_sdk.js:35872:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:50958/dart_sdk.js:35906:35)
at Object._microtaskLoop (http://localhost:50958/dart_sdk.js:40778:13)
at _startMicrotaskLoop (http://localhost:50958/dart_sdk.js:40784:13)
at http://localhost:50958/dart_sdk.js:36261:9"
My ignoredServiceScripts in part of firebase_core_web:
List<String> get _ignoredServiceScripts {
try {
JsObject ignored =
JsObject.fromBrowserObject('flutterfire_ignore_scripts');
if (ignored is Iterable) {
return (ignored as Iterable)
.map((e) => e.toString())
.toList(growable: false);
}
} catch (e) {
// Noop
}
return [];
}
I don't get this error while running my app on iOS, for example. Can you please help?
Update:
I changed JsObject.fromBrowserObject('flutterfire_ignore_scripts') to JsObject.fromBrowserObject(context['flutterfire_ignore_scripts']), so it doesn't fail with this error anymore, it does fail with another one (both on web, iOS, Android):
"Error: Expected a value of type 'Object', but got one of type 'Null'
at Object.throw_ [as throw] (http://localhost:59214/dart_sdk.js:5080:11)
at Object.castError (http://localhost:59214/dart_sdk.js:5039:15)
at Object.cast [as as] (http://localhost:59214/dart_sdk.js:5356:17)
at Object.as (http://localhost:59214/dart_sdk.js:6603:31)
at get [_ignoredServiceScripts] (http://localhost:59214/packages/firebase_core_web/firebase_core_web.dart.lib.js:147:65)
at firebase_core_web.FirebaseCoreWeb.new._initializeCore (http://localhost:59214/packages/firebase_core_web/firebase_core_web.dart.lib.js:182:27)
at _initializeCore.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at [_initializeCore] (http://localhost:59214/packages/firebase_core_web/firebase_core_web.dart.lib.js:177:20)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:59214/packages/firebase_core_web/firebase_core_web.dart.lib.js:199:36)
at initializeApp.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:59214/packages/firebase_core_web/firebase_core_web.dart.lib.js:198:20)
at initializeApp (http://localhost:59214/packages/firebase_core/firebase_core.dart.lib.js:105:59)
at initializeApp.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at Firebase.initializeApp (http://localhost:59214/packages/firebase_core/firebase_core.dart.lib.js:104:20)
at create (http://localhost:59214/packages/wa_flutter_questionnaire/data/firebase/firebase_core_service.dart.lib.js:26:49)
at create.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at FirebaseCoreService.create (http://localhost:59214/packages/wa_flutter_questionnaire/data/firebase/firebase_core_service.dart.lib.js:25:20)
at http://localhost:59214/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1903:130
at get_it_helper.GetItHelper.new.singletonAsync (http://localhost:59214/packages/injectable/src/get_it_helper.dart.lib.js:117:18)
at $36initGetIt (http://localhost:59214/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1903:16)
at $36initGetIt.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at Object.$36initGetIt [as $initGetIt] (http://localhost:59214/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1900:18)
at configureDependencies (http://localhost:59214/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1918:32)
at configureDependencies.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at Object.configureDependencies (http://localhost:59214/packages/wa_flutter_questionnaire/domain/theme_manager.dart.lib.js:1917:18)
at preinit (http://localhost:59214/packages/wa_flutter_questionnaire/main.dart.lib.js:55:16)
at preinit.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at Object.preinit (http://localhost:59214/packages/wa_flutter_questionnaire/main.dart.lib.js:52:18)
at main$ (http://localhost:59214/packages/wa_flutter_questionnaire/main_local.dart.lib.js:18:18)
at main$.next (<anonymous>)
at runBody (http://localhost:59214/dart_sdk.js:40660:34)
at Object._async [as async] (http://localhost:59214/dart_sdk.js:40691:7)
at main$ (http://localhost:59214/packages/wa_flutter_questionnaire/main_local.dart.lib.js:17:18)
at http://localhost:59214/web_entrypoint.dart.lib.js:37:33
at Object._checkAndCall (http://localhost:59214/dart_sdk.js:5279:16)
at Object.dcall (http://localhost:59214/dart_sdk.js:5284:17)
at http://localhost:59214/dart_sdk.js:140291:18
at Generator.next (<anonymous>)
at http://localhost:59214/dart_sdk.js:40641:33
at _RootZone.runUnary (http://localhost:59214/dart_sdk.js:40511:59)
at _FutureListener.thenAwait.handleValue (http://localhost:59214/dart_sdk.js:35438:29)
at handleValueCallback (http://localhost:59214/dart_sdk.js:35999:49)
at _Future._propagateToListeners (http://localhost:59214/dart_sdk.js:36037:17)
at [_completeWithValue] (http://localhost:59214/dart_sdk.js:35872:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:59214/dart_sdk.js:35906:35)
at Object._microtaskLoop (http://localhost:59214/dart_sdk.js:40778:13)
at _startMicrotaskLoop (http://localhost:59214/dart_sdk.js:40784:13)
at http://localhost:59214/dart_sdk.js:36261:9"

vercel nextjs deployment build error: How to debug?

I'm a beginner deploying a basic nextjs app with vercel.
This error is occurring in the node_modules files, not in any code that I have written.
How should I go about debugging this?
TypeError: Cannot read properties of undefined (reading 'page')
at /vercel/path0/node_modules/next/dist/export/index.js:223:40
at Array.filter (<anonymous>)
at /vercel/path0/node_modules/next/dist/export/index.js:222:43
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
at async /vercel/path0/node_modules/next/dist/build/index.js:1168:21
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
at async /vercel/path0/node_modules/next/dist/build/index.js:1044:17
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20)
at async Object.build [as default] (/vercel/path0/node_modules/next/dist/build/index.js:65:29)```

Flutter FirebaseMessaging onBackgroundMessage Null check operator used on a null value

I'm building an app with firebase with push notifications so the app was running but after I used "flutter clean" this error appears without changing and piece of code
E/flutter (14812): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
E/flutter (14812): #0 MethodChannelFirebaseMessaging.registerBackgroundMessageHandler (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:180:53)
E/flutter (14812): #1 FirebaseMessagingPlatform.onBackgroundMessage= (package:firebase_messaging_platform_interface/src/platform_interface/platform_interface_messaging.dart:102:16)
E/flutter (14812): #2 FirebaseMessaging.onBackgroundMessage (package:firebase_messaging/src/messaging.dart:73:31)
E/flutter (14812): #3 main (package:mitaa/main.dart:37:21)
the error appears in the package firebase_messaging: ^11.2.6
https://firebase.flutter.dev/docs/messaging/usage/
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
void main() {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}
Blockquote

Clean install of Strapi/Next.js starter throws errors on preview mode

I am running a clean install of the strapi-starter-next-corporate starter app. When I try to access a preview of the unpublished "secret" page, I get this error:
[develop:frontend] error - ReferenceError: locale is not defined
[develop:frontend] at preview (C:\Users\username\Projects\projectname\frontend\.next\server\pages\api
\preview.js:36:5)
[develop:frontend] at Object.apiResolver (C:\Users\username\Projects\projectname\frontend\node_module
s\next\dist\server\api-utils.js:101:15)
[develop:frontend] at runMicrotasks (<anonymous>)
[develop:frontend] at processTicksAndRejections (internal/process/task_queues.js:95:5)
[develop:frontend] at async DevServer.handleApiRequest (C:\Users\username\Projects\projectname\fronte
nd\node_modules\next\dist\server\next-server.js:775:9)
[develop:frontend] at async Object.fn (C:\Users\username\Projects\projectname\frontend\node_modules\n
ext\dist\server\next-server.js:666:37)
[develop:frontend] at async Router.execute (C:\Users\username\Projects\projectname\frontend\node_modu
les\next\dist\server\router.js:205:32)
[develop:frontend] at async DevServer.run (C:\Users\username\Projects\projectname\frontend\node_modul
es\next\dist\server\next-server.js:846:29)
[develop:frontend] at async DevServer.run (C:\Users\username\Projects\projectname\frontend\node_modul
es\next\dist\server\dev\next-dev-server.js:355:20)
[develop:frontend] at async DevServer.handleRequest (C:\Users\username\Projects\projectname\frontend\
node_modules\next\dist\server\next-server.js:292:20) {
[develop:frontend] page: '/api/preview'
[develop:frontend] }
[develop:backend ] [2022-02-09 09:48:13.162] http: POST /graphql (9 ms) 400
[develop:frontend] TypeError: Cannot read property 'global' of undefined
[develop:frontend] at getGlobalData (C:\Users\username\Projects\projectname\frontend\.next\server\pag
es\_app.js:628:22)
[develop:frontend] at runMicrotasks (<anonymous>)
[develop:frontend] at processTicksAndRejections (internal/process/task_queues.js:95:5)
[develop:frontend] at async Function.MyApp.getInitialProps (C:\Users\username\Projects\projectname\fr
ontend\.next\server\pages\_app.js:249:24)
[develop:frontend] at async Object.loadGetInitialProps (C:\Users\username\Projects\projectname\fronte
nd\node_modules\next\dist\shared\lib\utils.js:69:19)
[develop:frontend] at async Object.renderToHTML (C:\Users\username\Projects\projectname\frontend\node
_modules\next\dist\server\render.js:314:17)
[develop:frontend] at async doRender (C:\Users\username\Projects\projectname\frontend\node_modules\ne
xt\dist\server\next-server.js:1149:38)
[develop:frontend] at async C:\Users\username\Projects\projectname\frontend\node_modules\next\dist\se
rver\next-server.js:1241:28
[develop:frontend] at async C:\Users\username\Projects\projectname\frontend\node_modules\next\dist\se
rver\response-cache.js:64:36
My preview url:
http://localhost:3000/api/preview?secret=xxxxxxxxxxxxxxxxx&slug=secret
I also tried:
http://localhost:3000/api/preview?secret=xxxxxxxxxxxxxxxxx&slug=/secret
My .env file for my next app:
NEXT_PUBLIC_STRAPI_API_URL=http://localhost:1337
PREVIEW_SECRET=xxxxxxxxxxxxxxxxx
My .env file for my strapi app:
FRONTEND_URL=http://localhost:3000
FRONTEND_PREVIEW_SECRET=xxxxxxxxxxxxxxxxx
The I18 plugin and the preview code seem not to be totally integrated. Has anyone else encountered this?
Windows 11
Node.js v14.18.3
I think that you found a bug. The reason is that strapi-starter-next-corporate uses locale inside API route /frontend/pages/api/preview.js. Next.js does not support locale inside API route. You can read more about it here.

firebase admin sdk authentication fails locally with getaddrinfo ENOTFOUND

Having a local developed cloud function and started it locally via:
firebase emulators:start
The cloud function is here:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL:"https://test1-xxx.firebaseio.com",
});
I get:
FirebaseAppError: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
at FirebaseAppError.FirebaseError [as constructor] (/Users/dgang/study/test/functions/node_modules/firebase-admin/lib/utils/error.js:42:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/dgang/study/test/functions/node_modules/firebase-admin/lib/utils/error.js:88:28)
at new FirebaseAppError (/Users/dgang/study/test/functions/node_modules/firebase-admin/lib/utils/error.js:122:28)
at /Users/dgang/study/test/functions/node_modules/firebase-admin/lib/firebase-app.js:121:23
at processTicksAndRejections (internal/process/task_queues.js:89:5) { errorInfo: {
code: 'app/invalid-credential',
message: 'Credential implementation provided to initializeApp() via ' +
'the "credential" property failed to fetch a valid Google ' +
'OAuth2 access token with the following error: "Error ' +
'fetching access token: Error while making request: ' +
'getaddrinfo ENOTFOUND metadata.google.internal. Error ' +
'code: ENOTFOUND".' }, codePrefix: 'app' }
I defined GOOGLE_APPLICATION_CREDENTIALS as needed but this does not help.
I tried to google the issue but without avail.
What needs to be fixed here?
Update:
When i require the service account explicitely it works:
var serviceAccount = require("service-account.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL:"https://test1-xxx.firebaseio.com",
});
but this is a dangerous option

Resources