Add browser shim for node:events module#9141
Conversation
|
PR has been updated to handle |
node:events module
|
Hello! 👋 We’ve extensively looked at your PR and manually tested it, and it turned out that, surprisingly, You can test this via
We came up with a very hardcoded fix, left for your consideration in this branch. This allows mkdir tmp
cd tmp
mkdir -p node_modules/events
# edit node_modules/events/index.js to print/return something
# edit index.js to contain `const e = require('events') ; console.log(e)`
node index.jsThis is also true for To test that the fix itself actually works and # in your pouchdb repo with our change:
$ npm run test-webpack
$ cd packages/node_modules/pouchdb-browser
$ npm pack
# copy resulting tarball to some other empty directory and cd there
$ npm init # and yes all the things
$ npm i < TARBALL_FILENAME >
# inspect the `node_modules` folder, `events` is presentAside from the fix, the branch also contains another commit with a small cleanup change. We hope this helps to land this fix in the next release! Thanks for your continued work on PouchDB 🙏 |
TODO
import 'pouchdb-events'===import 'node:events'?This seems to be a common issue:
pouchdb-utilsdepends oneventsnpm package for the browser build, but does not declare it as a dependency. #8985I think it was introduced by 404346b, which upgrade from webpack 1 to webpack 5. From the webpack docs:
Alternatively, it may come from rollup.
Hopefully:
Closes #8968
Closes #8985
Closes #8989
Closes #9072
Closes #9078