Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pouchdb authentication giving error: Could not find module pouchdb-authentication imported from (require) #164

Closed
flynsequeira opened this issue Aug 16, 2017 · 8 comments

Comments

@flynsequeira
Copy link

did npm install pouchdb-authentication

Further at this step,
var PouchDB = require("pouchdb");
PouchDB.plugin(require('pouchdb-authentication'));

Could not find module pouchdb-authentication imported from (require)

@flynsequeira
Copy link
Author

Static method worked. The other 2 didn't.

@Sushmitha-KK
Copy link

I am facing the exact same issue. But the static method also doesn't work in my case. It gives an error at the '.login()' function, saying that the function doesn't exist.
in index.html

<script src="{{rootURL}}resources/js/pouchdb-authentication/dist/pouchdb.authentication.min.js"></script>

in app/authenticator/application.js
let remoteDb = new PouchDB("http://"+id+":"+password+"@localhost:5984/healthicate/", { skipSetup: true });
this.db = remoteDb;
....
this.db.login(username, password).then((response) => {...

@ptitjes
Copy link
Collaborator

ptitjes commented Nov 20, 2017

@flynsequeira, @Sushmitha-KK Have you found what was you problem ?

@tomasvarg
Copy link

I've encountered the db.login function doesn't exist error after upgrading project's dependencies - it's just an assumption but as one of the upgrades was Webpack going from v2 to v3 and babel-loader v6 to v7, i think it might something to do with how one of them is treating default exports, anyways: by the force of console.log I've encountered that the result of require('pouchdb-authentication') is as expected on the server part run by babel-node but { default: ... } on the client part run by webpack (the project is based on js-stack-boilerplate where substantial amount of code is shared between server & client) ... so the solution for me was simply to use es6 module import syntax:

import PouchDB from 'pouchdb';
import PouchDBAuth from 'pouchdb-authentication';

PouchDB.plugin(PouchDBAuth)

or if you insist on require:

const PouchDBModule = require('pouchdb');
const PouchDBAuthModule = require('pouchdb-authentication');

const PouchDB = 'default' in PouchDBModule ? PouchDBModule.default : PouchDBModule;
const PouchDBAuth = 'default' in PouchDBAuthModule ? PouchDBAuthModule.default : PouchDBAuthModule;

PouchDB.plugin(PouchDBAuth)

There is some debate concerning the issues with default exports on the webpack's github, at the time still opened though.

@ptitjes
Copy link
Collaborator

ptitjes commented Jan 15, 2018

@tomasvarg Would you mind trying the following just to be sure ?

import * as PouchDB from 'pouchdb';
import * as PouchDBAuth from 'pouchdb-authentication';

PouchDB.plugin(PouchDBAuth)

Also, please be specific as to what version of PouchDB and PouchDB Authentication you are using!

@tomasvarg
Copy link

@ptitjes as done so the result is the same as using require: ok on babel-node & { default: ... } on webpack-powered client.

Versions:

"pouchdb": "6.4.1"
"pouchdb-authentication": "1.1.0"
"webpack": "3.10.0",
"webpack-dev-server": "2.11.0"
"babel-loader": "7.1.2",

@ptitjes
Copy link
Collaborator

ptitjes commented Jan 16, 2018

@tomasvarg It just appeared to me that you were giving a solution. So if it just works using ES6 imports, maybe I could close this bug. @flynsequeira ?

@ptitjes ptitjes closed this as completed Feb 23, 2018
@lakinmohapatra
Copy link

I am facing issue . Angular 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants