Can't use PouchDB with Ionic 2 RC1

I follow http://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-ionic-2/ this tutorial but i get require is not defined error in Chrome. I read https://github.com/driftyco/ionic/issues/8356 that topic but i can’t get anywhere… The tutorial with Ionic Beta is working as expected but RC1 fails. Does it have to be sooo difficult to get each step in Ionic2? Is there a tutorial/clue to make a simple connection with PouchDB?

Solution:

I installed latest Ionic App Scripts build tools (which uses Webpack instead of Rollup) with this command:

npm install @ionic/app-scripts@beta

Then run npm run build to test the new build process. Source topic

And then imported PouchDB like this:

import * as PouchDB from 'pouchdb'; // no need to use require() anymore :slight_smile:

Then tried this in a simple class:

  private _db;
  private _record;
  ionViewDidLoad() { // WARNING: tutorial uses old "ionViewLoaded" which is not working anymore
    console.log('starting db');
    this._db = new PouchDB('birthday2');
    this._record = { name: 'emre' };
    this._db.post(this._record);
    console.log("record ok");
  }

And voila! Hope this helps someone :slight_smile:

Note: I’ve also added typings of PouchDB, i’m not sure if it was necessary:

typings install --global --save dt~pouchdb dt~pouchdb-adapter-websql dt~pouchdb-browser dt~pouchdb-core dt~pouchdb-http dt~pouchdb-mapreduce dt~pouchdb-node dt~pouchdb-replication