Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property ‘then’ of undefined while using ionic-v4 with Sqlite #67

Open
ferdiaddawy opened this issue Jan 28, 2019 · 6 comments

Comments

@ferdiaddawy
Copy link

I found the problem

core.js:15714 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
TypeError: Cannot read property 'then' of undefined

import { Injectable } from '@angular/core';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';
import { Platform } from '@ionic/angular';

@Injectable({
providedIn: 'root'
})
export class ApilocalService {

database : SQLiteObject = null;
constructor(
private platform: Platform,
public sqlite: SQLite
) {

this.platform.ready().then(() => {
  this.sqlite.create({
    name: 'data.db',
    location: 'default'
  }).then((db: SQLiteObject) => { --> problem here

  })


});

}

`import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { SQLite } from '@ionic-native/sqlite/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule
],
providers: [
StatusBar,
SQLite,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
`

can anybody help me to solve this.

Regards

@mrterry06
Copy link

@ferdiaddawy Did you ever get the answer to your question? I'm experiencing the same thing. Before diving into the plugin code I was gonna take the logic out of the service contructor and add it to a method. Once this was completed I was then going to use use APP_INITALIZER to call to that method. But..if you have an easier fix please let me know

@mrterry06
Copy link

mrterry06 commented Feb 6, 2019

Nevermind I figured out the issue. For anyone in the future, this happens when cordova is not available. if you go to the plugin code, check the create method, and log the function checkAvailability, it will return an error node. if you google that, you should find the answer. Theres no if else statement. So it literally does nothing when cordova is not available instead of return an error message thats useful.

@mehthaf
Copy link

mehthaf commented Feb 20, 2019

@mrterry06 provide the solution please im stuck with that
capture

@mrterry06
Copy link

@mehthaf ionic cordova run browser. Cordova needs plugins to run in browser. This command should install the browser plugins. You could also run android or ios to
Make it available. You can even mock out SQLite for development. https://www.techiediaries.com/mocking-native-sqlite-plugin/

@brodycj brodycj transferred this issue from storesafe/cordova-sqlite-storage Apr 7, 2019
@brodycj
Copy link

brodycj commented Apr 7, 2019

Transferred to xpbrew/cordova-sqlite-storage-help.

@brodycj brodycj reopened this Apr 7, 2019
@joeljimenez
Copy link

Presento el mismo error, pero estoy usándolo con capacitor , no estoy con cordova.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants