Repository navigation
Description
src/index.cjs should be the same file in every repo, a drop-in that works out the right shape itself instead of each repo hand-writing .default unwraps and attached aliases (which drift from the ESM exports):
"use strict";
if (!process.features?.require_module) {
const error = new Error(`<pkg>: require() needs Node.js ^20.19.0 or >=22.13.0 (this is ${process.version}). On older Node.js, load the package with import() instead.`);
error.code = "ERR_REQUIRE_ESM";
throw error;
}
// Same exports as `import`. One distinct exported value (aliases of it count once) comes back as that value,
// so require(x)(...) works; anything else comes back as the module object ({ default, ...named }).
const esm = require("./index.mjs");
const values = new Set(Object.keys(esm).filter((key) => key !== "__esModule").map((key) => esm[key]));
module.exports = values.size === 1 ? values.values().next().value : esm;Only the package name in the message and the Node floor change per repo. The same pattern applies to other CJS entries (e.g. src/drizzle.cjs → ./drizzle.mjs).
Behaviour, checked by running it against the published packages:
| Package | Generic shim returns | Today |
|---|---|---|
| fix-headers, stubborn-tcp, sizeofvar, mxnet-control, droidsock, prettier-plugin-jsonv | the single value | same |
sqlite-wasm, vitest-runner (and the other plain require("./index.mjs") repos) |
module object | same |
| uuid, wisp, node-android-tv-remote, holdmytask | module object | default only: changes, a major each |
| eslint-plugin-jsonv | module object | the plugin object: changes, check first |
For the four that change, require(x)(…) callers break and need require(x).default (or the named export), so each repo adopts the shim in its next major.
eslint-plugin-jsonv exports the plugin plus JsonvSourceCode. ESLint's legacy config loader require()s a plugin and may expect the plugin object itself. Check whether it unwraps .default; if it doesn't, that repo keeps a plugin-specific shim as the one documented exception.
To do: put the shim in docs/conventions/package-layout.md (same file as #582) and the example template, then file one issue per repo to adopt it (all repos with a src/index.cjs; it's a no-op change for every repo that already returns the same shape).
Activity
docs(package-layout): index.cjs re-exports the ESM module unchanged
Shinrai commentedon Nov 26, 2026
Refined rule: if the ESM entry exports one distinct value (aliases like
default+fixHeadersfor the same function count as one),src/index.cjsmay keep returning that value, sorequire(x)(…)keeps working. If it exports more than one distinct value,src/index.cjsis exactlymodule.exports = require("./index.mjs");.require()then returns the module object ({ __esModule: true, default, …named }):require(x).default,require(x).namedandconst { default: main, named } = require(x)all work, the same asimport * as.Checked against the published packages (distinct values in the ESM namespace):
UUIDandISSUER_CATEGORIESwispandwispSynccreateRemoteandcreateAndroidTVRemotedefaultis the plugin, plusJsonvSourceCode). ESLint's legacy config loaderrequire()s the plugin and expects the plugin object, so this may stay an exception.So the per-repo issues are for uuid, wisp, node-android-tv-remote and holdmytask (plus a look at eslint-plugin-jsonv).
[-]package-layout: the CJS wrapper must return the same module as ESM, never an unwrapped default[/-][+]package-layout: one generic CJS shim that returns the right shape for any package[/+]docs(package-layout): one generic index.cjs shim for every library
docs(package-layout): index.cjs re-exports the ESM module unchanged
docs(package-layout): one generic index.cjs shim for every library
docs(package-layout): ship dist/ as one file per module and use one g…
cldmv-bot commentedon Nov 26, 2026
Marked
status: implemented— resolved by #584, merged intonext. This issue closes automatically when that work ships to the default branch.release: v4.46.0 - add extra_build_os for a build check on other…