ITADN

Incorrect use of v.getDefault in to-json-schema

#1448Opennathancahill 创建于 2026-04-07
bug
N
nathancahillcommented
In `@valibot/to-json-schema`, `valibot` is _correctly_ marked as a peer dependency, and used for types throughout the package. However, in two locations, it's incorrectly used as code: https://github.com/open-circle/valibot/blob/d680d097bc112d3e4f5a2d08b30c4827c110ebb6/packages/to-json-schema/src/converters/convertSchema/convertSchema.ts#L493-L494 https://github.com/open-circle/valibot/blob/d680d097bc112d3e4f5a2d08b30c4827c110ebb6/packages/to-json-schema/src/converters/convertSchema/convertSchema.ts#L513-L514 This leads to `import * as v from "valibot";` being included at the top of the built package. When this is combined with the peer dependency, it throws errors if `valibot` is not installed. One option would be to switch to a dynamic import at runtime: ```ts async function maybeApplyDefault(jsonSchema: JsonSchema, valibotSchema: Schema) { try { const v = await import('valibot'); if (valibotSchema.default !== undefined) { jsonSchema.default = v.getDefault(valibotSchema); } } catch { // valibot not installed -> noop } } ```
1 条评论