Skip to content

Commit f19b46f

Browse files
authored
fix(docs): Add ESM requirements (#2984)
closes #2981 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Reordered README contents and added a new "TypeError: example is not a function" caveat with links 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 and refined prior releases with updated ESM guidance. * **Contributors** * Added contributor badges/entries. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 39cd60e commit f19b46f

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## Version 25
44

5+
### v25.5.3
6+
7+
- Updated environment requirements in the Readme:
8+
- Version 25 should be run in an ESM environment because it installs the Zod plugin using the `import` statement;
9+
- To ensure this, either set `type: module` in `package.json`, use `.mts` extension, or run using `tsx`/`vite-node`;
10+
- Although all Node.js versions support `require(ESM)`, `zod` remains a dual package with both CJS and ESM copies;
11+
- If your code uses `require("zod")` (CJS), it is not the same instance that the framework operates;
12+
- This can lead to `TypeError: example is not a function` and loss of metadata set by the `.meta()` method;
13+
- This issue was reported by [@squishykid](https://github.com/squishykid).
14+
515
### v25.5.2
616

717
- Added `z.function()` to the list of JSON-incompatible schemas:

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Start your API server with I/O schema validation and custom middlewares in minut
5959
5. [Graceful shutdown](#graceful-shutdown)
6060
6. [Subscriptions](#subscriptions)
6161
8. [Caveats](#caveats)
62-
1. [Excessive properties in endpoint output](#excessive-properties-in-endpoint-output)
62+
1. [TypeError: example is not a function](#typeerror-example-is-not-a-function)
63+
2. [Excessive properties in endpoint output](#excessive-properties-in-endpoint-output)
6364
9. [Your input to my output](#your-input-to-my-output)
6465

6566
See also [Changelog](CHANGELOG.md) and [automated migration](https://www.npmjs.com/package/@express-zod-api/migration).
@@ -85,6 +86,7 @@ Therefore, many basic tasks can be accomplished faster and easier, in particular
8586

8687
These people contributed to the improvement of the framework by reporting bugs, making changes and suggesting ideas:
8788

89+
[<img src="https://github.com/squishykid.png" alt="@squishykid" width="50px" />](https://github.com/squishykid)
8890
[<img src="https://github.com/jakub-msqt.png" alt="@jakub-msqt" width="50px" />](https://github.com/jakub-msqt)
8991
[<img src="https://github.com/misha-z1nchuk.png" alt="@misha-z1nchuk" width="50px" />](https://github.com/misha-z1nchuk)
9092
[<img src="https://github.com/GreaterTamarack.png" alt="@GreaterTamarack" width="50px" />](https://github.com/GreaterTamarack)
@@ -183,9 +185,13 @@ pnpm add -D @types/express @types/node @types/http-errors
183185

184186
## Environment preparation
185187

186-
Consider using the recommended `tsconfig.json` base for your project according to your Node.js version,
187-
for example [the base for Node.js 20+](https://github.com/tsconfig/bases/blob/main/bases/node20.json).
188-
Ensure having the following options in order to make it work as expected:
188+
Ensure running your code as [ESM](https://nodejs.org/api/esm.html#enabling) by either:
189+
190+
- setting `"type": "module"` in your `package.json`;
191+
- or using `.mts` file extension;
192+
- or using `tsx` or `vite-node` or similar tools.
193+
194+
Enable the following `compilerOptions` in your `tsconfig.json` to make it work as expected:
189195

190196
```json
191197
{
@@ -1389,6 +1395,11 @@ framework, [Zod Sockets](https://github.com/RobinTail/zod-sockets), which has si
13891395
There are some well-known issues and limitations, or third party bugs that cannot be fixed in the usual way, but you
13901396
should be aware of them.
13911397

1398+
## TypeError: example is not a function
1399+
1400+
If you face this error then [switch your environment to ESM](#environment-preparation).
1401+
See [issue 2981](https://github.com/RobinTail/express-zod-api/issues/2981) for details.
1402+
13921403
## Excessive properties in endpoint output
13931404

13941405
The schema validator removes excessive properties by default. However, Typescript
@@ -1397,13 +1408,9 @@ in this case during development. You can achieve this verification by assigning
13971408
reusing it in forced type of the output:
13981409

13991410
```typescript
1400-
import { z } from "zod";
1401-
1402-
const output = z.object({
1403-
anything: z.number(),
1404-
});
1411+
const output = z.object({ anything: z.number() });
14051412

1406-
endpointsFactory.build({
1413+
factory.build({
14071414
output,
14081415
handler: async (): Promise<z.input<typeof output>> => ({
14091416
anything: 123,

0 commit comments

Comments
 (0)