GithubHelp home page GithubHelp logo

Comments (25)

liquid36 avatar liquid36 commented on July 4, 2024 6

I made a webpack alias to the browser version file. Like this:

alias: {
  'pouchdb-promise': path.join(__dirname, '../node_modules/pouchdb-promise/lib/index.js')
},

from relational-pouch.

EvansMatthew97 avatar EvansMatthew97 commented on July 4, 2024 1

To get around this problem I commented out line 3 in lib/pouch-utils.js

'use strict';

//var Promise = require('pouchdb-promise'); <-- commented out
/* istanbul ignore next */
exports.once = function (fun) {

Not sure what the actual problem is, though.

from relational-pouch.

dmitri-wm avatar dmitri-wm commented on July 4, 2024 1

Think found where exactly issue is.
Here is used CommonJs require https://github.com/pouchdb-community/relational-pouch/blob/master/lib/pouch-utils.js#L3
And 'pouchdb-promise' which is required written with ES6 and exported as default.

So proper syntax will be
not

var Promise = require('pouchdb-promise')
but
var Promise = require('pouchdb-promise').default;

I saw there is https://github.com/59naga/babel-plugin-add-module-exports but can't setup it so it could help here.

Any ideas?

@lakinmohapatra did you sort out issue?

from relational-pouch.

fpfarina avatar fpfarina commented on July 4, 2024 1

@liquid36 good solution!! What it's great, no need to fork or make changes to the source code! Thx!

from relational-pouch.

freddydrodev avatar freddydrodev commented on July 4, 2024 1

@liquid36 where do you put that alias?

Hi guy I know it's a bit late but I have just faced the issue and base on #86 (comment). This is how I have managed:
I am using create-react-app
I have installed react-app-rewired react-app-rewire-aliases in order to be able to modify it. check the docs for more info:

yarn add react-app-rewired react-app-rewire-aliases -D

but basicaly this is the code to put in config-overrides.js in your root folder

const rewireAliases = require("react-app-rewire-aliases");
const path = require("path");

module.exports = function override(config, env) {
  config = rewireAliases.aliasesOptions({
    "pouchdb-promise": path.join(
      __dirname,
      "/node_modules/pouchdb-promise/lib/index.js"
    )
  })(config, env);

  return config;
};

from relational-pouch.

twincle avatar twincle commented on July 4, 2024 1

Here's a workround:

    const utils = require('relational-pouch/lib/pouch-utils.js');
    utils.Promise = window.Promise;
    PouchDB.plugin(require('relational-pouch'));

You can manully change the default Promise object before PouchDB plugin it.
This is because angular uses ZoneAwarePromise as the default Promise.
Normally, it will work fine. But in some unknown (just I don't know) reasons, ZoneAwarePromise become a module with a default property who wraps the real ZoneAwarePromise Object.

from relational-pouch.

dmitri-wm avatar dmitri-wm commented on July 4, 2024

Same problem with angular 4 and ionic 2. @MrPutuLips comment helps, but it's not a good idea to comment out script :)
code sample which causes this error


import { Injectable } from '@angular/core';
import PouchDB from 'pouchdb';
import * as cordovaSqlitePlugin from 'pouchdb-adapter-cordova-sqlite';
import * as relationalPouch from 'relational-pouch'

@Injectable()

export class DbConnector{
  private db = null;

  public connect(){
    PouchDB.plugin(cordovaSqlitePlugin);
    PouchDB.plugin(relationalPouch);
    PouchDB.debug.enable('*');

    this.db = new PouchDB('gre-app');
    this.setSchema();
  }

  private setSchema() {
    this.db.setSchema([
        { singular: 'department', plural: 'departments' }
      ])
  }

  public getDb(){
    return this.db
  }
}

from relational-pouch.

danobot avatar danobot commented on July 4, 2024

Facing this same problem.

from relational-pouch.

broerse avatar broerse commented on July 4, 2024

We updated pouchdb-promise to the newest version in v3.0.0

We like to know if this solves this issue.

from relational-pouch.

Prabuganesan avatar Prabuganesan commented on July 4, 2024

I have update version 3.0.0. But still this issue not solved.

from relational-pouch.

broerse avatar broerse commented on July 4, 2024

@Prabuganesan Thanks for testing. I will try to understand what is wrong. I don't use Angular and Ember is not showing this error so not sure where the bug is coming from.

from relational-pouch.

humbertocruz avatar humbertocruz commented on July 4, 2024

Here too with NextJS

from relational-pouch.

jlami avatar jlami commented on July 4, 2024

@dmitri-wm is correct. This module is not ES6 yet and should respect the fact that pouchdb-promise is. So a .default after the require is the correct way to go for now.

from relational-pouch.

jlami avatar jlami commented on July 4, 2024

I think this is a transpile problem. Our tests wont work with .default and the browserified version in /dist should also be correct without it.

But since ES6 is the future, it might be a good idea to rewrite this whole plugin and setup js:next in package.json which should help those that expect ES6 modules. Otherwise the babel plugin that @dmitri-wm mentioned seems good

I saw there is https://github.com/59naga/babel-plugin-add-module-exports but can't setup it so it could help here.

But I don't know anything about angular and how it transpiles, so I'm sorry I can't help there.

from relational-pouch.

tim-field avatar tim-field commented on July 4, 2024

Same issue in a React project using Create React App

from relational-pouch.

tim-field avatar tim-field commented on July 4, 2024

This might be a silly question but can't we just rely on native promises now ?
https://github.com/pouchdb-community/relational-pouch/blob/master/lib/pouch-utils.js#L3 ( just removing this line fixes everything up for me )

If you don't have promise support in your target build in 2018 then chances are that you are already polyfilling them earlier in your build step ?

from relational-pouch.

luca147 avatar luca147 commented on July 4, 2024

The only solution is changing relational-pouch/lib/pouch-utils.js line 3: var Promise = require('pouchdb-promise');

to this: var Promise = require('pouchdb-promise').default;

????

Thanks!

from relational-pouch.

Prabuganesan avatar Prabuganesan commented on July 4, 2024

from relational-pouch.

luca147 avatar luca147 commented on July 4, 2024

: ( very bad....

how can we work with this solution, so that all the members of the team can have that change without needing to modify it each one of them???

from relational-pouch.

luca147 avatar luca147 commented on July 4, 2024

Well i decided i will not use this plugin, it have lot of bugs, i think use only pouch is more efficient.
Thanks

from relational-pouch.

509dave16 avatar 509dave16 commented on July 4, 2024

@luca147 You will need to create a fork of this repo and modify it yourself to have the change like what @rwein did in his fork: https://github.com/rwein/relational-pouch/commit/6b525a3ca3eea891a4a12c3b195e7c730be67e80

Then install the package using the github repo.

Or simply use the fork I pointed out in the link above.

This way you and all your team members should have the change.

from relational-pouch.

luca147 avatar luca147 commented on July 4, 2024

@509dave16 thx man, I decided not to use the plugin, as I told you in the other thread.. thx a lot

from relational-pouch.

p4bl1t0 avatar p4bl1t0 commented on July 4, 2024

@liquid36 where do you put that alias?

from relational-pouch.

liquid36 avatar liquid36 commented on July 4, 2024

Here!
It's depends on your webpack configurations.

from relational-pouch.

easychen avatar easychen commented on July 4, 2024

@liquid36 where do you put that alias?

Hi guy I know it's a bit late but I have just faced the issue and base on #86 (comment). This is how I have managed:
I am using create-react-app
I have installed react-app-rewired react-app-rewire-aliases in order to be able to modify it. check the docs for more info:

yarn add react-app-rewired react-app-rewire-aliases -D

but basicaly this is the code to put in config-overrides.js in your root folder

const rewireAliases = require("react-app-rewire-aliases");
const path = require("path");

module.exports = function override(config, env) {
  config = rewireAliases.aliasesOptions({
    "pouchdb-promise": path.join(
      __dirname,
      "/node_modules/pouchdb-promise/lib/index.js"
    )
  })(config, env);

  return config;
};

this works for me . if you use customize-cra , config-overrides.js might like this :


const {
    override,
   ...,
    addWebpackAlias
  } = require("customize-cra");

const path = require("path");
  
  module.exports = {
    webpack: override(
        addWebpackAlias({"pouchdb-promise": path.join(
          __dirname,
          "/node_modules/pouchdb-promise/lib/index.js"
        )})
    )
  };

from relational-pouch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.