apache / apache/pouchdb

`pouchdb-utils` depends on `events` npm package for the browser build, but does not declare it as a dependency.

Open
#8,985 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Issue

Bundle `pouchdb-utils` using a typical bundler. For example, bundle using `esbuild` with the following commands:

```shell
mkdir -p /tmp/dependency-repro && cd /tmp/dependency-repro
npm init -y
npm install pouchdb-utils esbuild
echo 'export * from "pouchdb-utils";' | npx esbuild --format=esm --target=es6 --bundle --minify
```

This results in:

```
✘ [ERROR] Could not resolve "events"

node_modules/pouchdb-utils/lib/index-browser.es.js:2:25:
2 │ import EventEmitter from 'events';
╵ ~~~~~~~~

The package "events" wasn't found on the file system but is built into node.
Are you trying to bundle for node? You can use "--platform=node" to do that,
which will remove this error.

1 error
```

Note that the suggested `--platform=node` argument is not appropriate, as this is happening while bundling the browser build.

It seems the browser build of `pouchdb-utils` expects the package `events` from `npm` to be installed as a polyfill for `node`'s built-in `node:events` module. This is not good practice, and I think `pouchdb-utils` should explicitly declare this dependency so that its browser build has all required dependencies.

(It may also be wise to conditionally load the polyfill only when `node:events` is not available, but that isn't necessary for this issue.)

### Info

- Environment: macOS 14.6.1
- Platform: macOS 14.6.1
- Adapter: N/A
- Server: N/A

### Reproduce

See above

--------

I would try to submit a PR to address this, but I can't figure out how `package.json` for `pouchdb-utils` is synthesized.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.