Skip to content

Emit .js extension in generated files#138

Closed
ioxde wants to merge 1 commit intocodama-idl:mainfrom
ioxde:emit-js-extensions
Closed

Emit .js extension in generated files#138
ioxde wants to merge 1 commit intocodama-idl:mainfrom
ioxde:emit-js-extensions

Conversation

@ioxde
Copy link
Copy Markdown
Contributor

@ioxde ioxde commented Apr 10, 2026

Trimmed down version of #134 without the nodenext changes.

Adding .js is required with certain typescript configurations / ESM modules. This change only adds support for all import patterns.

Nice LLM generated table:

environment without .js with .js
moduleResolution: "node" (legacy) works works
moduleResolution: "bundler" works works
moduleResolution: "node16" fails works
moduleResolution: "nodenext" fails works
CommonJS (require()) works works

Closes #127

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: e8e778e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/renderers-js Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lorisleiva
Copy link
Copy Markdown
Member

Hmm as discussed here:

In practice, program client maintainers are going to want to expose their packages as ESM and CJS builds which is best done as CJS first to avoid TypeScript issues. That being said, I'd be okay accepting an option for this that defaults to keeping export paths the way they are.

This is not what this PR does so I'll close but feel free to open a new one that does what we discussed.

@lorisleiva lorisleiva closed this Apr 13, 2026
@ioxde
Copy link
Copy Markdown
Contributor Author

ioxde commented Apr 14, 2026

Sorry I meant to address that in an edit but didn't get around to it. I can add an option but I think it should be default enabled. .js is what is supported by both CJS and ESM. Excluding the .js actually makes the generated typescript less compatible with various tsconfig.json configurations, while adding .js makes it compatible with (almost) all* (that I am aware of) configurations.

It is required for any consumer that is using tsc to emit their files for use with ESM.

More typescript references: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html
https://nodejs.org/api/esm.html#mandatory-file-extensions

* I was able to find one usage example that .js is NOT the correct pattern, and that's Node's native TypeScript execution which requires .ts extensions (extensionless and .js do not work). They love throwing a wrench in the ecosystem 😂

If you'd still rather have it off by default let me know, I can do a followup PR no problem.

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.

Add option to generate clients with useEsmExtensions

2 participants