Comments (15)
Jesus christ
from zod-to-json-schema.
I have re-produced the same issue. I have made a project in Stackblitz please take a look at it.
Steps
npm install && npx next dev
Visit : /api/test
You can see the logs
from zod-to-json-schema.
Can't reproduce. Please check if this looks right https://github.com/StefanTerdell/zod-to-json-schema/blob/master/test/issues.test.ts#L6
from zod-to-json-schema.
from zod-to-json-schema.
I am seeing this issue as well. What version of node were used in the repo and your response @StefanTerdell @Rajavasanthan ?
from zod-to-json-schema.
@jhiester-shell It's 18.18.0 in the playground @Rajavasanthan provided
from zod-to-json-schema.
can you test on 20.10.0?
from zod-to-json-schema.
I just tested the provided example on 16.20.0, 18.18.0 and 20.10.0 with node commonjs, node esm and ts-node (10.9.1, defaults only) with no issue. closing until someone can reproduce this.
from zod-to-json-schema.
I have a very similar issue with node 18.18.0 and Next 14. Simple schema, same recursion error as above.
const zodSchema = z.object({
questions: z.array(
z.object({
question: z.string().describe("One question on the test"),
})
).length(5).describe("List of 5 questions on the test"),
});
Using with ai^2.2.20
const functionCallingModel = llm.bind({
functions: [
{
name: "create_test",
description: "Create a 5 question test. The questions should slowly increase in difficulty.",
parameters: zodToJsonSchema(zodSchema, "Test"),
},
],
function_call: { name: "create_test" },
});
error:
⨯ RangeError: Maximum call stack size exceeded
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
at Module.zodToJsonSchema (webpack-internal:///(rsc)/./node_modules/zod-to-json-schema/dist/esm/index.js:43:107)
...
from zod-to-json-schema.
@StefanTerdell Reproduction is to use the link @Rajavasanthan posted, but change line 7 (the import) to use a named import:
import { zodToJsonSchema } from 'zod-to-json-schema';
Here is an updated StackBlitz. As before, visit /api/test
, and now it breaks as described:
I suspect ESM weirdness in Webpack in my and @rheaton64's cases (I'm bundling for a Firebase function using Webpack 4), and whatever next is doing in @Rajavasanthan's case (swc, but then Stackblitz doesn't support it, so falls back to Webpack?).
Answer might just be: don't import it like that! But if so, that'd be a BC-break, no? (Unless the project doesn't consider bundled usage as part of API stability?). There's also third-party code I can't control that imports it like this (e.g. fastify-type-provider-zod) so those aren't easy to fix.
The issue test won't pick it up because it's not going through package.json
nor bundling.
I think this is why packages usually add an ESM version at the next major version bump (because it's unpredictable which of the exports
listed in package.json
a bundler will choose, and it's hard to test a package under bundlers.)
from zod-to-json-schema.
Same issue here when using Next.js 14 with monaco editor. The crash only happens in prod. I am using zod-to-json-schema
for autocompletion in monaco. The code looks something like this:
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
...monaco.languages.json.jsonDefaults.diagnosticsOptions,
validate: true,
schemas: [
...(monaco.languages.json.jsonDefaults.diagnosticsOptions.schemas ?? []),
{
uri: jsonSchemaUri,
fileMatch: [modelPath],
schema: zodToJsonSchema(schema),
},
],
It used to work, but started crashing after I updated from 3.21.4 to 3.22.0.
from zod-to-json-schema.
This diff might fix it: 82d339e#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80L2
Happy to try a canary release and report if I get the same crash in next start
as for 3.22.0
.
from zod-to-json-schema.
@kachkaev Sure, I just published 3.22.1@beta
from zod-to-json-schema.
It worked! After updating zod-to-json-schema
to 3.22.1-beta.0
, I can no longer observe a crash in next start
🎉
from zod-to-json-schema.
Nice. I just released it on @latest tag as well. Keeping this open for a bit in case we get stragglers, but fingers crossed it should be fixed
So I can understand why the recursive export caused an overflow... What I don't get is what it had to do with named/default exports
from zod-to-json-schema.
Related Issues (20)
- Why doesn't get optional in path HOT 1
- Helper: how to converse file type? HOT 2
- OpenAPI fix for a nullable ref using allOf HOT 2
- Reused schema generates invalid $ref (?) HOT 8
- Docs for `.default` on schema definition HOT 1
- Plans on implementing draft 2020-12? HOT 3
- Preserve the order of properties HOT 2
- additionalProperties should be conditional with zod object strict() not passthrough() HOT 3
- [New feature] Add support for example field HOT 2
- esm support HOT 3
- reference root level schemas only HOT 2
- Represent `Map`s as records HOT 6
- Support `readonly()` HOT 5
- Upgrade Zod to fix `npm audit` vulnerability HOT 4
- Generated regex cannot be used with unicode flag HOT 2
- How can I specify the format? HOT 7
- Types with default not added to required? HOT 3
- z.pipe can create impossible validation schemas HOT 3
- Incorrect $ref for self-referencing types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zod-to-json-schema.