Skip to content

Dual ESM and CommonJS package support - #11

Open
igoramadas wants to merge 1 commit into
masterfrom
ayla/esm-cjs-dual-package-1426
Open

Dual ESM and CommonJS package support#11
igoramadas wants to merge 1 commit into
masterfrom
ayla/esm-cjs-dual-package-1426

Conversation

@igoramadas

Copy link
Copy Markdown
Owner

The library now ships as a dual ESM + CommonJS package, so it works in ESM-only projects while require("anyhow") keeps working.

Changes

  • Compile both lib/esm (native ESM) and lib/cjs (CommonJS)
  • Add a package exports map so import logger from "anyhow" and const logger = require("anyhow") both resolve to the logger instance
  • Load optional loggers (winston, bunyan, pino, gcloud, chalk) through a runtime require that works in both module systems
  • Keep CommonJS require() returning the instance (not { default: instance })
  • Add compatibility tests that import/require the built package, including simulated ESM-only and CJS consumers

Usage

const logger = require("anyhow")
import logger from "anyhow"
Open in Web Open in Cursor 

Ship both ESM and CJS builds so import and require work, and load optional
loggers in a way that is compatible with ESM-only projects.

Co-authored-by: Igor Ramadas <igor@ramadas.net>
@igoramadas
igoramadas marked this pull request as ready for review September 4, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants