Skip to content

fix(pkg): add default condition to exports for CJS resolvers#23

Merged
khaliqgant merged 1 commit intomainfrom
fix/cjs-exports-condition
Apr 15, 2026
Merged

fix(pkg): add default condition to exports for CJS resolvers#23
khaliqgant merged 1 commit intomainfrom
fix/cjs-exports-condition

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Apr 15, 2026

Summary

  • Add a default condition to both . and ./sdk exports, pointing at the same ESM entry as import.
  • Does not change the runtime — package is still type: module and dist is still ESM. This only closes a CJS resolution gap.

Why

The exports map previously declared only types and import conditions:

"exports": {
  ".": {
    "types": "./dist/index.d.ts",
    "import": "./dist/index.js"
  }
}

When a CJS caller — or a tooling path-walker like tsx's resolveTsPaths — lands on this package, Node's CJS resolver picks condition set ['require','node','default'], finds none of them, and errors with ERR_PACKAGE_PATH_NOT_EXPORTED. That surfaced as a confusing "No 'exports' main defined" failure inside agent-relay run's tsx fallback, even though no code was actually trying to require('agent-trajectories').

With default added, the CJS resolver finds a target. If someone really does try to require() the ESM build it will fail with a clear ERR_REQUIRE_ESM, which is the expected ESM-interop error — much better than the misleading "no exports main" message.

The companion fix on AgentWorkforce/relay (#741) removes the tsx fallback in most cases by using node --experimental-strip-types first. This PR is belt-and-suspenders for any other downstream that hits the same resolver path.

Test plan

  • npm run build still passes
  • npm test still passes
  • From a CJS project, require.resolve('agent-trajectories') no longer throws ERR_PACKAGE_PATH_NOT_EXPORTED

🤖 Generated with Claude Code


Open with Devin

The exports map declared only `types` and `import` conditions,
which made CJS resolution fail with ERR_PACKAGE_PATH_NOT_EXPORTED
when a CJS caller (or a tooling path-walker like tsx's
resolveTsPaths) landed on the package. Adding a `default`
condition pointing at the same ESM entry lets Node's CJS
resolver find a match and then fail at load time with a
clearer ESM-interop error instead of a misleading
"no exports main defined".

Functionally this does not make the package dual-mode — it's
still `type: module` and the dist is ESM — but it closes the
CJS resolution gap that was breaking downstream tsx users.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@khaliqgant khaliqgant merged commit 70df6ee into main Apr 15, 2026
6 checks passed
@khaliqgant khaliqgant deleted the fix/cjs-exports-condition branch April 15, 2026 11:28
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