Search code examples
javascripttypescriptangularpouchdbsystemjs

PouchDB Authentication library in Angular2 Cli project


I am having trouble importing the PouchDB Authentication library (https://github.com/nolanlawson/pouchdb-authentication) into my Angular2 Cli Typescript project.

I have added this to my typings:

declare module "pouchdb-authentication" {}

My system-config.ts file contains in map:

'pouchdb-authentication': 'vendor/pouchdb-authentication/dist/',

and in packages:

"pouchdb-authentication": {
  main: "pouchdb.authentication.js",
  defaultExtension: "js"
}, 

I am attempting to use it like so:

PouchDB.plugin(require('pouchdb-authentication'));

I have also tried:

import * as PouchDBAuthentication from 'pouchdb-authentication';

Currently, I am getting this error in my console:

zone.js:461: Unhandled Promise rejection: (SystemJS) TypeError: AMD module http://localhost:4200/vendor/pouchdb-authentication/dist/pouchdb.authentication.js did not define

Any ideas would be much appreciated! Thank you!


Solution

  • Are you sure you want to pull in dist/pouchdb.authentication.js as opposed to using the CommonJS package? dist/ contains the UMD package, in which case it looks like SystemJS is trying to load it as AMD.

    Edit: nevermind, I see I forgot to build it as UMD. I'll fix that and then you should be able to use the dist/ just fine (although again, I don't think you need to since SystemJS should be able to consume CommonJS just fine).

    Opened an issue here: https://github.com/nolanlawson/pouchdb-authentication/issues/103

    Edit: fixed in pouchdb-authentication 0.5.2, please try again