Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: work around Ajv module bug in generated code (#256)
JavaScript module inconsistency strikes again. In some cases, Ajv will inject `require` calls into generated code even if you ask it to generate ESM. [This is a bug][0]. For example, here's something it adds if you use [the string `minLength` or `maxLength` properties][1]: // ... const func2 = require("ajv/dist/runtime/ucs2length").default; // ... That won't work in an ESM environment. As a workaround, I inject the following into our generated code: import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); This, along with moving `ajv` to production dependencies, should work around this issue until the bug is fixed. [0]: ajv-validator/ajv#2209 [1]: https://json-schema.org/understanding-json-schema/reference/string#length
- Loading branch information