Skip to content

W2: package entry points work in CommonJS, ESM and bundlers - #6

Merged
czypnt merged 2 commits into
mainfrom
w2-exports
Nov 22, 2026
Merged

czypnt merged 2 commits into
mainfrom
w2-exports

Conversation

@czypnt

@czypnt czypnt commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

W2: package entry points

What. No exports map, so Node ESM loaded the CommonJS build dist/index.js for import: import Datalyr from '@datalyr/api' gave the whole module object and new Datalyr() threw Datalyr is not a constructor. dist/index.mjs and dist/index.d.mts were built and shipped but Node never used them.

Change (package.json only):

  • exports: . → import { types dist/index.d.mts, default dist/index.mjs }, require { types dist/index.d.ts, default dist/index.js }; plus ./package.json and ./dist/* so existing deep imports (@datalyr/api/dist/index.js) keep resolving.
  • main, module and types unchanged (older tools and TypeScript node10 resolution still use them).
  • CHANGELOG entry under Unreleased.

Test. Proof projects below (built tarball installed into real projects). No unit test: nothing in src/ changed.

Proof: built tarball vs published 1.3.4

npm ci && npm run build && npm pack on this branch, then npm install <tarball> into throwaway projects (typescript 5.9.3, @types/node 20.19.9, Node 26.5.0). "Before" is npm install @datalyr/api@1.3.4.

Project Check Before (1.3.4) After (this PR)
CommonJS new (require('@datalyr/api').default)(…) and new (require(…).Datalyr)(…) works works
Node ESM import Datalyr from → new Datalyr() error: Datalyr is not a constructor works
Node ESM import { Datalyr } from → new Datalyr() works works
TS moduleResolution: node16, ESM project tsc --noEmit on new Datalyr() (default) and new Named() (named) error TS2351 This expression is not constructable works
TS moduleResolution: bundler same works works

Tarball contents

npm pack --dry-run file list before (origin/main package.json) and after: 7 files each, identical paths and sizes; the only difference is package.json (1061 → 1372 bytes).

LICENSE 1073
README.md 3256
dist/index.d.mts 6408
dist/index.d.ts 6408
dist/index.js 21899
dist/index.mjs 20824
package.json 1372

Changes to what the SDK sends

None. Entry points only.

Not done

Nothing.

🤖 Generated with Claude Code


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

czypnt and others added 2 commits November 22, 2026 15:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@czypnt
czypnt merged commit 8708ffc into main Nov 22, 2026
3 checks passed
@czypnt
czypnt deleted the w2-exports branch November 22, 2026 23:18
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.

1 participant