index.js reassigns module.exports early on:
module.exports = {
transform,
filter: transform
}
but the browser auto-registration at the bottom of the file uses the free exports
binding instead of module.exports:
if (typeof window !== 'undefined' && window.PouchDB) {
window.PouchDB.plugin(exports)
}
Reassigning module.exports never updates the separate exports shortcut variable
(a classic Node CJS gotcha), so at that point exports is still the original empty
object, not { transform, filter }. window.PouchDB.plugin({}) then throws:
Invalid plugin: got "[object Object]", expected an object or a function
This line only runs when typeof window !== 'undefined', so it's dead code under
normal require() in Node — which is presumably why it's gone unnoticed. It only
surfaces when the package is actually bundled (e.g. with esbuild) and run in a real
browser, since transform-pouch doesn't ship a prebuilt browser build itself.
Repro: bundle index.js for the browser (esbuild index.js --bundle --platform=browser --format=iife) with pouchdb.min.js already loaded as window.PouchDB, then load the
bundle — throws immediately on load.
Fix is one line: use module.exports instead of exports on that final line. Happy
to open a PR if useful.
index.jsreassignsmodule.exportsearly on: