pouchdb-community/pouchdb-quick-search

Ionic 2 Crypto Issue

daveywc opened this issue · 1 comments

When trying to use pouchdb-quick-search in an Ionic 2 app I got an error in pouch-utils at the following line:
var crypto = require('crypto');

Installing crypto via NPM did not help.

I worked around this error by installing crypto-js via NPM and then modifying the exported MD5 function to the following (the changes simply comment out and replace the first and last lines of code):

/* Start HS Modifications */
//var crypto = require('crypto');
var cryptojs_md5 = require('crypto-js/md5');
var md5 = require('md5-jkmyers');
exports.MD5 = function (string) {
/* istanbul ignore if */
if (process.browser) {
    return md5(string);
}
//return crypto.createHash('md5').update(string).digest('hex');
return cryptojs_md5(value).toString(CryptoJS.enc.Hex);
};
/* End HS Modifications */

Depending on your build environment it may not recognize the "browser" field in package.json which is supposed to handle this automatically. You can also omit it at the webpack/browserify/rollup config level.