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

Webpack: Promise is not a constructor #81

Open
cah-ricksuggs opened this issue Dec 1, 2017 · 6 comments
Open

Webpack: Promise is not a constructor #81

cah-ricksuggs opened this issue Dec 1, 2017 · 6 comments

Comments

@cah-ricksuggs
Copy link

Great library, I am really getting into the pouchdb ecosystem!

I received a error message stating that "Promise is not a constructor." After investigating the issue, I noticed that pouch-quick-search depends on an outdated version of pouchdb-promise, which created a version conflict in my webpack bundle.

Someone proposed just modifying pouch-utils to require('pouchdb-promise').default but that would break when running in nodejs.

I was able to workaround the issue by augmenting the webpack configuration of my angular app, by adding a resolve alias to always pull in the newer version of pouchdb-promise, and using the index.js rather than index.es.js

const path = require('path');
const webpackDefault = require('@ionic/app-scripts/config/webpack.config');
const webpackMerge = require('webpack-merge');

const customConfig = {
  dev: {
    resolve: {
      alias: {
        'pouchdb-promise$': "pouchdb-promise/lib/index.js"
      }
    }
  },
  prod: {
    resolve: {
      alias: {
        'pouchdb-promise$': "pouchdb-promise/lib/index.js"
      }
    }
  }
};

module.exports = webpackMerge(webpackDefault, customConfig);

Is there an easy way to update this library to distribute a ES6 module version for webpack to use, and a ES5 (CommonJS?) version for nodejs to use? I noticed other pouchdb libraries are using the "main" and "module" package.json properties to achieve this. I'd be happy to open a pull request after getting some direction.

@silverbackdan
Copy link

silverbackdan commented Feb 15, 2018

Thanks so much for posting the results f your investigation on this. I'm sure I'm not the only one you've saved loads of debugging time for.

Here's a slightly sorter config without the webpack-merge dependency if using Ionic. I've left in another alias too @environment which is part of a solution to set environment variables.

const path = require('path');
const webpackConfig = require('@ionic/app-scripts/config/webpack.config.js');

module.exports = function () {
  webpackConfig[process.env.IONIC_ENV].resolve.alias = {
    "@environment": path.resolve(__dirname + '/../../src/config/config.' + process.env.IONIC_ENV + '.ts'),
    'pouchdb-promise$': "pouchdb-promise/lib/index.js"
  };
  return webpackConfig;
};

@david-dev0415
Copy link

Thanks so much for posting the results f your investigation on this. I'm sure I'm not the only one you've saved loads of debugging time for.

Here's a slightly sorter config without the webpack-merge dependency if using Ionic. I've left in another alias too @environment which is part of a solution to set environment variables.

const path = require('path');
const webpackConfig = require('@ionic/app-scripts/config/webpack.config.js');

module.exports = function () {
  webpackConfig[process.env.IONIC_ENV].resolve.alias = {
    "@environment": path.resolve(__dirname + '/../../src/config/config.' + process.env.IONIC_ENV + '.ts'),
    'pouchdb-promise$': "pouchdb-promise/lib/index.js"
  };
  return webpackConfig;
};

Hi, I have problems. I am new to this and I have the same error, where I paste this code that they have put. Help me please

@daveywc
Copy link

daveywc commented Mar 12, 2019

@davidspalaciof You need to add a file somewhere in your project that contains the code above. Then reference that file in your package.json as follows:

"config": { "ionic_webpack": "./config/webpack.config.js" },

In the example above I have a folder named "config" at the root of my project that contains a file named webpack.config.js.

@daveywc
Copy link

daveywc commented Mar 12, 2019

@silverbackdan Your solution works very nicely - thank you. @cah-ricksuggs thanks to you for the original solution.

@isumix
Copy link

isumix commented Sep 30, 2019

Hi, I get the same issue using pouchdb-replication-stream.
But I could't find how to resolve alias in create-react-app without ejecting.
So I've just imported plugin from dist like:
var replicationStream = require('pouchdb-replication-stream/dist/pouchdb.replication-stream.min.js');
Hope this helps someone.
Is there any better way of doing it?

@sureshvv
Copy link

Hi, I get the same issue using pouchdb-replication-stream.
But I could't find how to resolve alias in create-react-app without ejecting.
So I've just imported plugin from dist like:
var replicationStream = require('pouchdb-replication-stream/dist/pouchdb.replication-stream.min.js');
Hope this helps someone.
Is there any better way of doing it?

Is there an explanation for why this works?

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

No branches or pull requests

6 participants