Skip to content

fix: correct exports map to match actual build output#3

Merged
asachs01 merged 2 commits into
mainfrom
fix/exports-map-mjs
May 20, 2026
Merged

fix: correct exports map to match actual build output#3
asachs01 merged 2 commits into
mainfrom
fix/exports-map-mjs

Conversation

@asachs01
Copy link
Copy Markdown
Member

Problem

Closes #2. Installing the package and import-ing it failed with Cannot find module .../dist/index.mjs.

Root cause: a mismatch between package.json and what tsup actually builds.

package.json claimed actually published
importdist/index.mjs does not exist
requiredist/index.js exists, but it's the ESM build
maindist/index.js ESM, mislabeled as CJS entry
moduledist/index.mjs does not exist

Because package.json has "type": "module", tsup names the ESM output index.js and the CJS output index.cjs — it never emits .mjs. The exports map was written for the opposite (no-"type": "module") convention.

Fix

Align main/module/exports with the real dist/ output:

  • import./dist/index.js (ESM)
  • require./dist/index.cjs (CJS)
  • CJS consumers now get ./dist/index.d.cts types instead of the ESM ./dist/index.d.ts

Verification

Built locally; both entry points resolve:

  • ESM: import('./dist/index.js') → exports resolve ✅
  • CJS: require('./dist/index.cjs') → exports resolve ✅

semantic-release will cut a 1.0.4 patch and update CHANGELOG.md on merge.

asachs01 added 2 commits May 20, 2026 09:55
The exports/main/module fields pointed at dist/index.mjs, which tsup
never produces. With "type": "module" set, tsup emits the ESM build as
index.js and the CJS build as index.cjs. Node resolved `import` to the
non-existent index.mjs and threw "Cannot find module".

Align main/module/exports with the real output, and route CJS consumers
to index.d.cts instead of the ESM index.d.ts.

Fixes #2
Unit and integration tests run against src/ via TypeScript and never
load dist/ or resolve the package.json exports map, so a broken exports
map (issue #2) passes every other check.

Add scripts/smoke-test.mjs, which packs the tarball, installs it into a
throwaway directory, and loads it by package name through both import
and require. Wired into CI after the test step and exposed as the
test:smoke npm script.
@asachs01
Copy link
Copy Markdown
Member Author

Added a package smoke test (scripts/smoke-test.mjs, npm run test:smoke) and wired it into CI after the test step.

It packs the tarball, installs it into a throwaway directory, and loads @wyre-technology/node-superops by name through both import and require — the path that unit/integration tests (which run against src/ via TypeScript) never exercise. Verified it catches the issue #2 class of bug: had import still resolved to the phantom dist/index.mjs, the ESM step would fail with ENOENT.

@asachs01 asachs01 merged commit d36fdd8 into main May 20, 2026
3 checks passed
@asachs01 asachs01 deleted the fix/exports-map-mjs branch May 20, 2026 14:45
github-actions Bot pushed a commit that referenced this pull request May 20, 2026
## [1.0.5](v1.0.4...v1.0.5) (2026-05-20)

### Bug Fixes

* correct exports map and add package smoke test ([#3](#3)) ([d36fdd8](d36fdd8)), closes [#2](#2)
asachs01 added a commit that referenced this pull request May 20, 2026
…#6)

Salvages the still-relevant pieces of the abandoned fix/review-medium
branch (its exports-map fix and smoke test already landed via #3/#5):

- Regenerate package-lock.json via `npm audit fix`, clearing 16 of 19
  dev-dependency advisories (incl. the critical/high vite findings).
  The remaining 3 live inside npm's own bundled deps under
  semantic-release and are not resolvable from here.
- tsup `target` node18 -> node22, matching `engines.node` (>=22).
- config.test.ts: replace `as any` with `as unknown as SuperOpsRegion`.

No production dependencies were affected; the published package is
unchanged at runtime.
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.

Installation not pulling .mjs files causing "Cannot find module" error

1 participant