Skip to content

Conversation

@alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Nov 20, 2025

TODO

  • add a test which fails against existing codebase similar to how linked issues fail, and passes with the updates in this PR
  • add a test for node-js builds to show that import 'pouchdb-events' === import 'node:events'

This seems to be a common issue:

I think it was introduced by 404346b, which upgrade from webpack 1 to webpack 5. From the webpack docs:

Webpack 5 no longer polyfills Node.js core modules automatically which means if you use them in your code running in browsers or alike, you will have to install compatible modules from npm and include them yourself.

Alternatively, it may come from rollup.

Hopefully:

Closes #8968
Closes #8985
Closes #8989
Closes #9072
Closes #9078

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Nov 20, 2025

Less convinced now:

PR has been updated to handle events dependency like other browser-specific polyfills via new pouchdb-events package.

> e1 = require('node:events'); e2 = require('./node_modules/events');
<ref *1> [Function: EventEmitter] {
  once: [Function: once],
  EventEmitter: [Circular *1],
  defaultMaxListeners: [Getter/Setter],
  init: [Function (anonymous)],
  listenerCount: [Function (anonymous)]
}
> e1
<ref *1> [Function: EventEmitter] {
  addAbortListener: [Function: addAbortListener],
  once: [AsyncFunction: once],
  on: [Function: on],
  getEventListeners: [Function: getEventListeners],
  getMaxListeners: [Function: getMaxListeners],
  EventEmitter: [Circular *1],
  usingDomains: true,
  captureRejectionSymbol: Symbol(nodejs.rejection),
  captureRejections: [Getter/Setter],
  EventEmitterAsyncResource: [Getter],
  errorMonitor: Symbol(events.errorMonitor),
  defaultMaxListeners: [Getter/Setter],
  setMaxListeners: [Function (anonymous)],
  init: [Function (anonymous)],
  listenerCount: [Function (anonymous)]
}
> e2
<ref *1> [Function: EventEmitter] {
  once: [Function: once],
  EventEmitter: [Circular *1],
  defaultMaxListeners: [Getter/Setter],
  init: [Function (anonymous)],
  listenerCount: [Function (anonymous)]
}
> e1.EventEmitter === e2.EventEmitter
false

@alxndrsn alxndrsn marked this pull request as draft November 20, 2025 11:15
@alxndrsn alxndrsn marked this pull request as ready for review November 20, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment