angular firebase build error when try ionic build - firebase

I got error when I tried to build ionic app.
Actually it wasn't a problem when I build in local, but when I check build status in ionic website, I got a bellow error.
using
angular5, ionic3
typescript: node_modules/angularfire2/firebase.app.module.d.ts, line: 10
Class 'FirebaseApp' incorrectly implements interface 'FirebaseApp'. Property
'automaticDataCollectionEnabled' is missing in type 'FirebaseApp'.
L9: export declare const FirebaseAppConfigToken: InjectionToken;
L10: export declare class FirebaseApp implements FBApp {
L11: name: string;
I have no idea. Should I downgrade firebase version?
UPDATE
I edited firebase.app.module.d.ts like the answer, but I got another error now. I edited .gitignore like this.
node_modules/*
!node_modules/angularfire2/firebase.app.module.d.ts
npm WARN angularfire2#5.0.0-rc.6.0 requires a peer of
#firebase/app#^0.1.6 but none was installed.
npm ERR! Invalid tar header. Maybe the tar is corrupted or it needs to
be gunzipped?
npm ERR! A complete log of this run can be found in: npm ERR!
/home/gitlab-runner/.npm/_logs/2018-04-20T07_49_29_110Z-debug.log

I solved with npm install #firebase/app#0.1.10.
Error doesn't happen and build success.

I solved this problem adding this line:
automaticDataCollectionEnabled: boolean;
on the file:
node_modules/angularfire2/firebase.app.module.d.ts
Final result:
import { InjectionToken } from '#angular/core';
import { FirebaseAppConfig } from './';
import { FirebaseApp as FBApp } from '#firebase/app-types';
import { FirebaseAuth } from '#firebase/auth-types';
import { FirebaseDatabase } from '#firebase/database-types';
import { FirebaseMessaging } from '#firebase/messaging-types';
import { FirebaseStorage } from '#firebase/storage-types';
import { FirebaseFirestore } from '#firebase/firestore-types';
export declare const FirebaseAppConfigToken: InjectionToken<FirebaseAppConfig>;
export declare class FirebaseApp implements FBApp {
name: string;
options: {};
automaticDataCollectionEnabled: boolean; // missing line
auth: () => FirebaseAuth;
database: () => FirebaseDatabase;
messaging: () => FirebaseMessaging;
storage: () => FirebaseStorage;
delete: () => Promise<any>;
firestore: () => FirebaseFirestore;
}
export declare function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string): FirebaseApp;

You have to add the property automaticDataCollectionEnabled to the FirebaseApp class (node_modules/angularfire2/firebase.app.module.d.ts).
export declare class FirebaseApp implements FBApp {
name: string;
options: {};
automaticDataCollectionEnabled: boolean; // add it like this
auth: () => FirebaseAuth;
database: () => FirebaseDatabase;
messaging: () => FirebaseMessaging;
storage: () => FirebaseStorage;
delete: () => Promise<any>;
firestore: () => FirebaseFirestore;
}

npm i #firebase/app#^0.1.6
This worked for me. As the warning says, firebase/app needs to be installed separately. Did the same and my project compiled successfully.

Related

Cannot find module 'firebase-functions/lib/encoder' from 'node_modules/firebase-functions-test/lib/providers/firestore.js'

Hey I am trying to unit test this cloud function right here:
import { logger, region, https } from "firebase-functions/v1";
import Message from "../types/message";
const helloWorldHandler = region("europe-west1").https.onCall((_, context) => {
if (context.app == undefined) {
throw new https.HttpsError("failed-precondition", "The function must be called from an App Check verified app.");
}
logger.info("Hello logs!", { structuredData: true });
const message: Message = {
text: "Hello from Firebase!",
code: 200,
};
return message;
});
export default helloWorldHandler;
with the following test:
import * as functions from "firebase-functions-test";
import * as path from "path";
const projectConfig = {
projectId: "myproject-id",
};
const testEnv = functions(projectConfig, path.resolve("./flowus-app-dev-fb-admin-sdk-key"));
// has to be after initializing functions
import helloWorldHandler from "../src/functions/helloworld";
import Message from "../src/types/message";
describe('Testing "helloWorld"', () => {
const helloWorld = testEnv.wrap(helloWorldHandler);
it("helloWorld does work", async () => {
const data = {};
const success: Message = await helloWorld(data);
expect(success.code).toBe(200);
});
});
When I run it with yarn test I receive the following error
Cannot find module 'firebase-functions/lib/encoder' from 'node_modules/firebase-functions-test/lib/providers/firestore.js'
Even though my function does not even use firestore in the first place?
Any ideas ?
I was facing a similar issue while trying to set up a unit testing environment for firebase cloud functions.
Mainly, after following all the steps on Firebase's docs, and running npm test
I would get the following error
Error [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './lib/encoder'
is not defined by "exports"
After stumbling on Farid's suggestion for this problem, I realized that, for some reason, npm i firebase-functions-test does not install the latest version of the module.
Try npm i firebase-functions-test#latest.

deploying cloud functions on firebase

I need to deploy a cloud function on firebase to set admin role:
this is my code:
typescript
"use strict";
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
exports.adAddminRole = functions.https.onCall((data) => {
return admin.auth().getUserByEmail(data.email).then((user) => {
return admin.auth().setCustomUserClaims(user.uid, {
admin: true,
}).then(() => {
return {
message: ` Success! ${data.email} as been made an admin`,
};
}).catch((err) => {
return err;
});
});
});
when I do firebase deploy --only functions, I get a lot of error messages:
../node_modules/#types/google.maps/index.d.ts:19:1 - error
TS6200: Definitions of the following identifiers conflict with
those in another file: DEFAULT, HORIZONTAL_BAR, DROPDOWN_MENU,
BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT, LEFT_BOTTOM,
LEFT_CENTER, LEFT_TOP, RIGHT_BOTTOM, RIGHT_CENTER, RIGHT_TOP,
TOP_CENTER, TOP_LEFT, TOP_RIGHT
19 declare namespace google.maps {
~~~~~~~
../node_modules/#types/googlemaps/reference/control.d.ts:1:1
1 declare namespace google.maps {
~~~~~~~
Conflicts are in this file.
it looks to me that they are not related directly to the cloud
function's code, I do not understand what is wrong

/node_modules/#prisma/client/runtime/index.js Module not found: Can't resolve 'async_hooks'

Bug description
Hello, I am new to Prisma. I have been trying to access Prisma database with nextjs. And every time I try to use PrismaClient from #prisma/client in a nextjs page, I have been seeing this error.
./node_modules/#prisma/client/runtime/index.js:26236:39
Module not found: Can't resolve 'async_hooks'
null
How to reproduce
Steps to reproduce the behavior:
My Schema file
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int #default(autoincrement()) #id
email String #unique
name String
password String
createdAt DateTime #default(now())
updatedAt DateTime #updatedAt
}
I created a migration and ran with the following commands
npx prisma migrate save --experimental
npx prisma migrate up --experimental
Then I also run npx prisma generate
This is my register.tsx file where I am accessing the prisma client
import { useState } from "react";
import { useRouter } from "next/router";
import { PrismaClient } from "#prisma/client";
const prisma = new PrismaClient();
interface RegisterProps {}
const Register: React.FC = ({}) => {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [name, setName] = useState("");
const submitHandler = async (e) => {
e.preventDefault();
try {
const user = await prisma.user.create({
data: {
email,
password,
name,
},
});
console.log(user);
router.push("/");
} catch (e) {
console.log(e);
}
};
return (
// my template goes here
);
};
export default Register;
After running this, I am getting this following error
/node_modules/#prisma/client/runtime/index.js
Module not found: Can't resolve 'async_hooks'
null
Expected behavior
I expect this code to build my page first. But it fails to do so and shows me the error in the title.
Prisma information
All of these information was included in the steps to reproduce part
Environment & setup
OS: Ubuntu
Database: MySQL
Node.js version: 14.05
Prisma version: 2.11.0
It's not possible to use PrismaClient directly on the frontend. You can only call it in the server-side methods that NextJS supports like this.

Firebase initialization error in VueJS Project

first time posting here. Also quite new to VueJS, know some Angular.
I ran into an error when initializing Firebase(first time getting this error) in my VueJS project:
That showed up briefly after click event, so I had to slow down my network to take screenshot.
I've included <script src="https://www.gstatic.com/firebasejs/5.5.5/firebase.js"></script> in index.html
I also installed firebase(latest version) via npm with --save
And created 2 files: firebaseInit.js and firebaseConfig.js(which contains the api key, etc for web app):
In firebaseInit.js:
import firebase from 'firebase';
import 'firebase/firestore';
import firebaseConfig from './firebaseConfig';
const firebaseApp=
firebase.initializeApp(firebaseConfig);
export default firebaseApp.firestore();
and put:
export default { the config key value pairs obtained
from Firebase console }
in firebaseConfig.js.
Extra info(though I don't think this is the source of the problem):
I imported firebase with import firebase as 'firebase' in the vue file I used firebase auth() and createUserWithEmailandPassword() in the methods property, but alert() doesn't work.
import firebase from 'firebase';
export default {
name: 'register',
data: function() {
return {
email: '',
password: ''
};
},
methods: {
register: function(e) {
firebase
.auth()
.createUserWithEmailAndPassword(this.email, this.password)
.then(
user => {
alert(`Account made for ${user.email}`);
this.$router.push('/');
},
err => {
console.log(err.message);
}
);
e.preventDefault();
}
}
};
You created your firebaseInit.js but since you never import or require it, is it never executed, thus resulting in a "firebase not initialized" error when you try to use the firebase you imported from the generic firebase module instead.
Use export default firebaseApp in your firebaseInit.js (and not firestore as you do now) and then import firebase from 'path/to/firebaseInit.js' for example.

User Management in Ionic2 with Meteor

as far as I know I need to run Accounts.createUser(...) and Meteor.loginWithPassword(...) to register and login users. Can someone please tell me which packages I need and how to import them correctly?
At the moment I do the import like this:
import 'meteor-client-side';
import 'accounts-base-client-side';
declare let Meteor;
declare let Accounts;
and get the errors
Accounts.createUser is not a function
Meteor.loginWithPassword is not a function
Install the necessary packages
npm install meteor-client-side --save
npm install accounts-base-client-side --save
npm install accounts-password-client-side --save
Import them in main.dev.ts/main.prod.ts with
import 'meteor-client-side';
import 'accounts-base-client-side';
import 'accounts-password-client-side';
Then you can declare Meteor/Accounts everywhere else with
declare let Meteor;
declare let Accounts;
and use it for example as
Accounts.createUser({ username: username, password: password }, (e: Error) => {
if (e) return this.handleError(e);
this.navCtrl.setRoot(MyPage, {}, {
animate: true
});
});
or
Meteor.loginWithPassword(username, password, (e: Error) => {
if (e) return this.handleError(e);
this.navCtrl.setRoot(MyPage, {}, {
animate: true
});
});

Resources