Skip to content

fix(docs): Add ESM requirements#2984

Merged
RobinTail merged 10 commits intomasterfrom
issue-2981-force-esm
Oct 3, 2025
Merged

fix(docs): Add ESM requirements#2984
RobinTail merged 10 commits intomasterfrom
issue-2981-force-esm

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Oct 2, 2025

closes #2981

Summary by CodeRabbit

  • Documentation

    • Reordered README, added a new "TypeError: example is not a function" caveat with link to environment guidance.
    • Updated setup guidance to prioritize ESM usage and explicit compiler options.
    • Simplified and reformatted examples and code snippets for clarity and consistency.
  • Changelog

    • Added v25.5.3 entry documenting ESM/CJS environment guidance and related notes.
  • Contributors

    • Added contributor badges/entries.

@RobinTail RobinTail added the documentation Improvements or additions to documentation label Oct 2, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 2, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Updated documentation: README reordered TOC, added contributor badges, new Caveats entry for "TypeError: example is not a function", replaced Node.js tsconfig guidance with ESM-run instructions, adjusted examples to use factory.build and simplified object construction; CHANGELOG added v25.5.3 with ESM/zod guidance.

Changes

Cohort / File(s) Summary
Docs: README updates
README.md
Reordered table of contents; added contributor badges; added Caveats entry "TypeError: example is not a function" linking to environment guidance/issue; replaced prior Node.js tsconfig guidance with ESM-run instructions (package.json "type": "module", .mts extensions, or tools like tsx/vite-node) and recommended tsconfig compilerOptions; adjusted examples to use factory.build and simplified object construction.
Docs: CHANGELOG entries
CHANGELOG.md
Added v25.5.3 entry documenting ESM/environment guidance and zod CJS/ESM nuances (cross-instance issues, error metadata); retained existing entries and clarified TS1479 resolution options (ESM switch, .mts, or tooling).

Sequence Diagram(s)

The changes are documentation-only and do not modify runtime control flow; no sequence diagram is provided.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

prevention

Poem

I nibble docs with curious paws,
I hop through notes and tidy the laws,
.mts and "type":"module" in sight,
strict and skipLibCheck make things right,
A rabbit grins — the README's bright. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely captures the primary update to documentation by indicating the addition of ESM requirements, which aligns directly with the changes made to the README and CHANGELOG.
Linked Issues Check ✅ Passed The documentation updates fully address issue #2981 by adding guidance on running consumer projects as ESM, explaining the cause of the “example is not a function” error and ensuring both express-zod-api and user code share the same Zod instance through clear instructions in README and CHANGELOG.
Out of Scope Changes Check ✅ Passed All modifications are confined to documentation files and directly support the ESM requirement objectives outlined in the linked issue without introducing unrelated or extraneous changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e710f25 and ef36a6b.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@RobinTail RobinTail marked this pull request as ready for review October 2, 2025 17:06
@RobinTail
Copy link
Copy Markdown
Owner Author

@coderabbitai, the cause of the issue is described here: #2981 (comment)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 2, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch the specific comment from issue #2981
gh api repos/RobinTail/express-zod-api/issues/comments/3360464495 --jq '.body'

Length of output: 570


@RobinTail, thank you for the clarification! I now understand the root cause:

The issue occurs when users run v25 (ESM-only) with CommonJS code. Since Express Zod API imports and patches Zod's ESM bundle with the .example() method, but user code compiled as CommonJS requires Zod's CJS bundle, they end up with two separate instances of Zod. The patched ESM instance has .example(), but the CJS instance used by the user's code does not.

This PR correctly addresses the issue by updating the documentation to emphasize ESM requirements, including:

  • Setting "type": "module" in package.json
  • Using .mts extension
  • Configuring proper compilerOptions for ESM output

The documentation changes will help users properly configure their projects to use ESM, ensuring they use the same Zod instance that Express Zod API patches.


✏️ Learnings added
Learnt from: RobinTail
URL: https://github.com/RobinTail/express-zod-api/pull/2984

Timestamp: 2025-10-02T17:19:20.584Z
Learning: In express-zod-api v25 (ESM-only), the `.example()` method error occurs when user code runs as CommonJS. Express Zod API patches Zod's ESM bundle with `.example()`, but CommonJS code requires a separate CJS bundle instance that lacks this patch. Users must configure their projects for ESM (package.json "type": "module", .mts extension, or proper compilerOptions) to use the patched Zod instance.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@coveralls-official
Copy link
Copy Markdown

coveralls-official Bot commented Oct 2, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling ef36a6b on issue-2981-force-esm
into 39cd60e on master.

@RobinTail
Copy link
Copy Markdown
Owner Author

@coderabbitai, compilerOptions do not make it ESM, only type in package.json or mts/mjs extension does. Alternative way is to run the cosumer's code using tsx or vite-node that use their own compilers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 2, 2025

Tip

For best results, initiate chat on the files or code changes.

@RobinTail, thank you for the correction! You're absolutely right—compilerOptions alone don't determine whether code runs as ESM. The module system is controlled by:

  • "type": "module" in package.json, or
  • Using .mts/.mjs file extensions, or
  • Running with tools like tsx or vite-node that provide their own compilation

I've updated my understanding accordingly.


✏️ Learnings added
Learnt from: RobinTail
URL: https://github.com/RobinTail/express-zod-api/pull/2984

Timestamp: 2025-10-02T17:42:48.813Z
Learning: In express-zod-api v25 (ESM-only), the `.example()` method error occurs when user code runs as CommonJS. Express Zod API patches Zod's ESM bundle with `.example()`, but CommonJS code requires a separate CJS bundle instance that lacks this patch. Users must run their code as ESM by: (1) setting `"type": "module"` in package.json, (2) using `.mts` or `.mjs` file extensions, or (3) using tools like `tsx` or `vite-node` that provide their own ESM-compatible compilation.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


⛔ Learnings removed
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-10-02T17:19:20.584Z
Learning: In express-zod-api v25 (ESM-only), the `.example()` method error occurs when user code runs as CommonJS. Express Zod API patches Zod's ESM bundle with `.example()`, but CommonJS code requires a separate CJS bundle instance that lacks this patch. Users must configure their projects for ESM (package.json "type": "module", .mts extension, or proper compilerOptions) to use the patched Zod instance.

🧠 Learnings used
Learnt from: RobinTail
PR: RobinTail/express-zod-api#0
File: :0-0
Timestamp: 2025-10-02T17:19:20.584Z
Learning: In express-zod-api v25 (ESM-only), the `.example()` method error occurs when user code runs as CommonJS. Express Zod API patches Zod's ESM bundle with `.example()`, but CommonJS code requires a separate CJS bundle instance that lacks this patch. Users must configure their projects for ESM (package.json "type": "module", .mts extension, or proper compilerOptions) to use the patched Zod instance.

Comment thread README.md Outdated
Comment thread CHANGELOG.md Outdated
@RobinTail RobinTail merged commit f19b46f into master Oct 3, 2025
10 of 11 checks passed
@RobinTail RobinTail deleted the issue-2981-force-esm branch October 3, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v25: example is not a function

1 participant