Skip to content

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

@lgarron

Description

@lgarron

Issue

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions