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-browser fails importing from 'events' #8641

Closed
jdfwarrior opened this issue May 25, 2023 · 5 comments
Closed

pouchdb-browser fails importing from 'events' #8641

jdfwarrior opened this issue May 25, 2023 · 5 comments
Assignees

Comments

@jdfwarrior
Copy link

jdfwarrior commented May 25, 2023

Issue

I just started on my project and still haven't actually used pouchdb at all yet. I'm in the middle of trying to upgrade a bunch of dependencies that are a few years old and don't even have the app running yet. One such update was migrating from webpack to vite as the build tool and I've come across a few issues.

We're using pouchdb-browser.

As defined in the documentation under the plugins section, says that pouchdb comes default with the pouchdb-replication plugin. pouchdb-replication however imports EE from 'events' which isn't available in the browser. It's throwing an error for me when the Changes class attempts to extend EE, because EE is null or not a constructor. Maybe this could be resolved by replacing imports for 'events' with something like 'eventemitter3'.

I also initially ran into an issue where the immediate lib (one of pouchdb-browser's dependencies) was throwing an error because the mutation lib within it attempts to initialize a Mutation variable to global.MutationObserver and vite doesn't provide shims for node like webpack does (reference: vitejs/vite#2778 (comment)). This can be resolved by importing a module that sets window.global = window and make it your first import. I know this is outside the scope of pouchdb, but if someone is running into these issues, they're potentially doing something similar and wanted to document the cause.

Info

  • Environment: browser
  • Platform: electron

Reproduce

I didn't go make a base case for this but I would think it should be easily reproducible by creating a new vite project and importing pouchdb-browser

@jatin-2708
Copy link

Please assign me this issue, very much excited to mark may first contribution to this.

@twitwi
Copy link

twitwi commented Oct 11, 2023

Thanks for the issue and the work in progress.
If anyone has the problem with import_events in the browser, I managed to work around it thanks to this issue, with npm install events.
And for the missing global, I updated my vite config

  define: { // https://stackoverflow.com/questions/72114775/vite-global-is-not-defined
    global: 'window',
  },

@alxndrsn
Copy link
Member

alxndrsn commented Nov 7, 2023

I also initially ran into an issue where the immediate lib (one of pouchdb-browser's dependencies) was throwing an error because the mutation lib within it attempts to initialize a Mutation variable to global.MutationObserver

This may be caused by calvinmetcalf/immediate#39.

@zaynekomichi
Copy link

Thanks for the issue and the work in progress. If anyone has the problem with import_events in the browser, I managed to work around it thanks to this issue, with npm install events. And for the missing global, I updated my vite config

  define: { // https://stackoverflow.com/questions/72114775/vite-global-is-not-defined
    global: 'window',
  },

This solved it for me, seems the events package is needed

@garethbowen
Copy link
Member

Fixed by #8849

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