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

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

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.

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.

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.

I am getting the same error . Please Fix this.

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;

4 Likes

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 Likes

Thanks friend for your help

1 Like

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: ?

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

This work for me! tks

This worked perfectly, thank you so so much holy cow.

i have some extra errors when installing:

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            ';' expected. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            ';' expected. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            Expression expected. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            'ObservableInput' only refers to a type, but is being used as a value here. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            Cannot find name 'infer'. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            Cannot find name 'T'. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            Cannot find name 'T'. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

*[14:16:25]  typescript: node_modules/rxjs/internal/types.d.ts, line: 81 *
*            'never' only refers to a type, but is being used as a value here. *

*      L81:  export declare type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;*

Hi, try the below version.
npm install rxjs@6.3.3 rxjs-compat@6.3.3 --save

2 Likes

Hi, I am working with File plugin, but always I have the same issue. I am using Ionic Version 4. I dont know what is wrong. TY.

not worked for me sir got again same error:Uncaught TypeError: Object(…) is not a function?

2 Likes

“rxjs”: “6.0.0”,
“rxjs-compat”: “^6.4.0”,
“sw-toolbox”: “3.6.0”,
“uglify-js”: “^3.5.10”,
“uk.co.workingedge.cordova.plugin.sqliteporter”: “^1.1.0”,
“webpack”: “^3.11.0”,
“zone.js”: “0.8.26”
},
“devDependencies”: {
@ionic/app-scripts”: “^3.1.11”,
“typescript”: “^2.6.2”
},

Check rxjs version and typescript version. its working for me