SQLite plugin not woking in ios simulator


#1

I have some problems with SQLite in ionic 2. It seems that my simulator cannot open the database because the sqlitePlugin is not found.

This is my app.component.ts (Same as a blank project from the todays date of ionic 2, typescript, but added with a simple SQLite database):

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import {StatusBar, Splashscreen, SQLite} from 'ionic-native';
import { HomePage } from '../pages/home/home';


@Component({
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
  rootPage = HomePage;

  constructor(platform: Platform) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      let db = new SQLite();
      db.openDatabase({
        name: 'data.db',
        location: 'default' // the location field is required
      }).then(() => {
        db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {
        }, (err) => {
          console.error('Unable to execute sql: ', err);
        });
      }, (err) => {
        console.error(err.toString());
        console.error('Unable to open database: ', err);
      });
      StatusBar.styleDefault();
      Splashscreen.hide();
    });
  }
}

I get an error in my console when I run
ionic emulate ios --livereload --consolelogs

[22:10:45]  console.log: Angular 2 is running in the development mode. Call enableProdMode() to enable the production 
            mode. 
[22:10:45]  console.warn: Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to 
            include cordova.js or run in a device/simulator 
[22:10:45]  console.warn: Native: tried calling Splashscreen.hide, but Cordova is not available. Make sure to include 
            cordova.js or run in a device/simulator 
[22:10:45]  console.error: ReferenceError: Can't find variable: sqlitePlugin 
[22:10:45]  console.error: Unable to open database: 

I have installed the cordova-sqlite-storage, followed this guide about SQLite, and followed the installation steps. I also did this xcode-select --install to make sure cordova would work with xcode, but nothing works.

Any ideas how I can make the sqlite plugin work with the emulator?


#2

Hi, i have the same problem. Did you find a solution?


#3

Hello. Unfortunately, I was not able to solve the problem. I decided to skip Ionic in my projects, and started using Angular 2 with a front-end framework instead. I am having such a hard time to get ionic to work. At least, that’s my experience.

I am using IndexedDb instead, utilizing the built-in-databse in the browsers. If you happen to solve the issue, feel free to post the answer here.