Using plugin Crypto-Pouch with PouchDB in RC0: Uncaught TypeError


#1

Before RC0 I used Crypto-Pouch for data encryption with PouchDB. After a couple of days I got PouchDB working with RC0 (following this topic).

Now my problem is, how to use the plugin Crypto-Pouch with PouchDB. Until beta.11 I used this code:

var PouchDB = require(‘pouchdb’).plugin(require(‘crypto-pouch’));

I tried the following steps:

npm install crypto-pouch --save

Because there exists no type definition for Crypto-Pouch, I tried to make a “Short-hand Definition” like described in this article by inserting the following line into src/declarations.d.ts:

declare module ‘crypto-pouch’;

In my provider I changed the line with require(…) (see above) to:

import PouchDB from ‘pouchdb’;
import CryptoPouch from ‘crypto-pouch’;

PouchDB.plugin(CryptoPouch);

Now there’s no error message using ionic serve, but I get no output and only the following message on the console:

Uncaught TypeError: Cannot read property ‘listenerCount’ of undefined

Is there anybody who can help me? Thanks in advance!


#2

+1, exactly the same error for me!


#3

I couldn’t find a solution until now. In case you are able to solve this problem, I would be very glad, if you share your solution here with me. Thanks in advance.


#4

After the latest updates in build process, I tried using crypto-pouch again. By using the following lines in my data provider, I get no error message first (not trying to encrypt the database):

import PouchDB from 'pouchdb';
import CryptoPouch from 'crypto-pouch';
PouchDB.plugin(CryptoPouch);

But if I insert the crypto command in the code, I get one of the following errors:

  1. Trying only myDB.crypto(‘password’); I get this error message: TypeError: Failed to execute ‘importKey’ on ‘SubtleCrypto’: The provided value is not of type ‘(ArrayBufferView or ArrayBufferView or Dictionary)’

  2. Trying this

     myDB.crypto('password').then((st) => { 
        console.log(st);
     }
    

    I get this error message: TypeError: Cannot read property ‘then’ of undefined

I think I’m a step ahead now, but I don’t know to solve it completely. Can you help me? Thanks in advance.


#5

After updating @ionic/app-scripts to 0.0.39 using

npm install @ionic/app-scripts@latest

and solving a problem of Crypto-Pouch by it’s author https://github.com/calvinmetcalf/crypto-pouch/issues/40 now it works for me by using the import like above.