Я пытаюсь импортировать клиентский SDK firebase JS (для имитации взаимодействия с пользователем) в облачную функцию, написанную на машинописном тексте, но у меня постоянно появляется ошибка отсутствующего пространства имен.
Согласно документы Я установил allowSyntheticDefaultImports
в true
в tsconfig. json для прохождения проверки типа.
Ошибка:
Error: Error occurred while parsing your function triggers.
Error: Cannot find the firebase namespace; be sure to include firebase-app.js before this library.
at /Users/theo/Desktop/flint-cf/functions/node_modules/@firebase/auth/dist/auth.js:372:285
at /Users/theo/Desktop/flint-cf/functions/node_modules/@firebase/auth/dist/auth.js:372:388
at Object.<anonymous> (/Users/theo/Desktop/flint-cf/functions/node_modules/@firebase/auth/dist/auth.js:372:394)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
Мой код:
import * as functions from 'firebase-functions';
// This import loads the firebase namespace.
import firebase from 'firebase/app';
// These imports load individual services into the firebase namespace.
import 'firebase/auth';
import 'firebase/functions';
// contants
import { CF_LOCATION } from '../../constants/cf_config';
firebase.initializeApp({
// my creds
});
export = functions
.region(CF_LOCATION)
.pubsub.schedule('every 2 minutes')
.onRun(context => {
try {
const user = firebase
.auth()
.signInWithEmailAndPassword('blabla@test.com', 'blablapass');
console.log('authenticated');
console.log(user);
} catch (err) {
console.log(err);
}
return null;
});
Что мне здесь не хватает?
Ура! :)