TypeError: Object(...) is not a function


#1

Hello guys, I was working in ionic 3 with angularfire2 , in the first app when I wrote this code:

try{
      this.WordList$ = this.afdatabase.list(`WordList/`)
.snapshotChanges()
.map(changes => {
return changes.map(c => ({
key: c.payload.key, ...c.payload.val()
}))
});
    }
catch(e) {
this.presentAlertError(e);
}

it working fine ,but in the second app when I wrote the same code it give me this error:

TypeError: Object(…) is not a function


Ionic Native Object(…) is not a function
#2

I’m receiving the same error using Ionic-Native, but i am using Google Plus. I am also using Ionic 4. Curious to see if anyone response.


#3

The error message is describing the exact error perfectly. The spread operator does not apply to an object. This means you are most likely using a version of TypeScript before 2.1? Because that’s when they added that feature: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#object-spread-and-rest

It’s possible that your other project was using a new version of TypeScript, but it’s also possible that in your old code c.payload.val() returned an array instead of an object, which has been supported for a very long time, ever since ES6/ES2015.


#4

I’m getting the same error for both the QR Scanner and the AppVersion package while using Ionic 4. Those are the only two packages I’ve tried to far so it doesn’t look package specific.


#5

I am getting the same error . Please Fix this.


#6

I found something that could help, I got the error with version rc.9 in angularfire2 so rolling back to rc.6 solved the error for me:
I first uninstalled firebase and angularfire2 with:

npm uninstall firebase
npm uninstall angularfire2

And then reinstalled again:

npm install angularfire2@5.0.0-rc.6
npm install firebase

and If you find error : ERROR Class ‘FirebaseApp’ incorrectly implements interface ‘App’
then add this line( automaticDataCollectionEnabled:boolean ) in this file.

\node_modules\angularfire2\firebase.app.module.d.ts

correct file contents:
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;
export declare class FirebaseApp implements FBApp {
name: string;
automaticDataCollectionEnabled:boolean
options: {};
auth: () => FirebaseAuth;
database: () => FirebaseDatabase;
messaging: () => FirebaseMessaging;
storage: () => FirebaseStorage;
delete: () => Promise;
firestore: () => FirebaseFirestore;
}
export declare function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string): FirebaseApp;


#7

I was also getting the same error for last two days and finally i caught the culprit.

This error started showing after upgrading the AngularFire2 to 5.0.0-rc.8 or higher and the reason is
rxjs 5 is no longer supported in AngularFire2 5.0.0-rc.8 or higher, upgrade to 6 and include rxjs-compat

npm i rxjs@^6.0 rxjs-compat


#8

Thanks friend for your help


#9

Sir i got same error but not using angular-fire in our app do you have know any another way to resolve this,i got below error
polyfills.js:3 Unhandled Promise rejection: Object(…) is not a function ; Zone: ?


#10

bro you are a god, thanks so much for your help!!!