From 84fba73051404038f06c6d97bedacadf10bf4c5a Mon Sep 17 00:00:00 2001 From: Srikar Sunchu Date: Mon, 14 Sep 2026 21:48:58 -0700 Subject: [PATCH] Add a default condition to every export so require('apecs') resolves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each exports entry declared only types and import, so a CommonJS resolver found no match and threw ERR_PACKAGE_PATH_NOT_EXPORTED — for Jest without ESM mode, ts-node in CJS mode, older bundler configs, and plain require in a Node script — even though Node >= 20.19, the engines floor, can load the ESM file through require(). Point default at the same ESM file for the root and the react, solid and internal subpaths; no CJS build is needed. check-bundle now resolves all four subpaths by package name through the exports map and loads the entry with require(), so a missing condition fails the post-build check instead of the first CJS consumer. Fixes #1 Co-Authored-By: Claude Fable 5.1 --- package.json | 12 ++++++++---- scripts/check-bundle.mjs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b8f18ff..e7472b5 100644 --- a/package.json +++ b/package.json @@ -22,19 +22,23 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.js" + "import": "./dist/index.js", + "default": "./dist/index.js" }, "./react": { "types": "./dist/react/index.d.ts", - "import": "./dist/react/index.js" + "import": "./dist/react/index.js", + "default": "./dist/react/index.js" }, "./solid": { "types": "./dist/solid/index.d.ts", - "import": "./dist/solid/index.js" + "import": "./dist/solid/index.js", + "default": "./dist/solid/index.js" }, "./internal": { "types": "./dist/internal.d.ts", - "import": "./dist/internal.js" + "import": "./dist/internal.js", + "default": "./dist/internal.js" } }, "files": [ diff --git a/scripts/check-bundle.mjs b/scripts/check-bundle.mjs index 8c9562a..9cd51e6 100644 --- a/scripts/check-bundle.mjs +++ b/scripts/check-bundle.mjs @@ -6,6 +6,7 @@ * npm run build && node scripts/check-bundle.mjs */ import { readFileSync, readdirSync } from 'node:fs'; +import { createRequire } from 'node:module'; import { join } from 'node:path'; const DIST = 'dist'; @@ -148,6 +149,24 @@ for (const [file, peer] of [ ); } +// Every entry must resolve for a CommonJS consumer too: the `default` condition +// is what a `require()` resolver matches, and Node ≥ 20.19 (the engines floor) +// loads the ESM file through it. Self-referencing by package name goes through +// the same exports map a consumer sees. +const require = createRequire(import.meta.url); +for (const subpath of ['apecs', 'apecs/react', 'apecs/solid', 'apecs/internal']) { + try { + require.resolve(subpath); + } catch (error) { + check(false, `${subpath} does not resolve for require(): ${error.code ?? error.message}`); + } +} +try { + check(typeof require('apecs').VERSION === 'string', 'require("apecs") does not load the entry'); +} catch (error) { + check(false, `require("apecs") throws: ${error.code ?? error.message}`); +} + if (failures.length > 0) { for (const failure of failures) { console.error(`✗ ${failure}`);