Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular dependencies? #118

Open
Carlos-err406 opened this issue Apr 29, 2024 · 6 comments
Open

Circular dependencies? #118

Carlos-err406 opened this issue Apr 29, 2024 · 6 comments
Labels

Comments

@Carlos-err406
Copy link

i get many circular dependencies from zod-to-json-schema when building with rollup

see image:
image

@jporre
Copy link

jporre commented Apr 30, 2024

This happens to me as well after upgrading to version 3.23.5 of ZOD
Sveltekit Project,
zod version -> zod3.23.5 on build :

Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/array.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/branded.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/catch.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/default.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/effects.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/map.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/map.js -> node_modules/zod-to-json-schema/dist/esm/parsers/record.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js -> node_modules/zod-to-json-schema/dist/esm/parsers/union.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/object.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/optional.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/promise.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/set.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js
Circular dependency: node_modules/zod-to-json-schema/dist/esm/parseDef.js -> node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js -> node_modules/zod-to-json-schema/dist/esm/parseDef.js

@StefanTerdell
Copy link
Owner

Thanks for opening an issue. Is this an actual problem?

@Carlos-err406
Copy link
Author

Thanks for opening an issue. Is this an actual problem?

more of an unconformity since it apparently does not break the app, just nasty logs at build

@willgottschalk
Copy link

Seems like a duplicate of #113

We're seeing this issue with v3.22.5. While I can't tell any noticeable issues, I'd prefer not to see these logs when building my app

@willgottschalk
Copy link

willgottschalk commented May 2, 2024

Also, this doesn't seem like a hard fix either.

import { JsonSchema7Type, parseDef } from "../parseDef.js";

The first import is a type and the second import could be made into an argument of the function to break the cycle. That's probably the least invasive way

import { ZodDefaultDef } from "zod";
import type { JsonSchema7Type, ParseDefFunc } from "../parseDef.js";
import { Refs } from "../Refs.js";

export function parseDefaultDef(
  _def: ZodDefaultDef,
  refs: Refs,
  parseDef: ParseDefFunc,
): JsonSchema7Type & { default: any } {
  return {
    ...parseDef(_def.innerType._def, refs),
    default: _def.defaultValue(),
  };
}

There are other ways to break cycles but this seems to require the least amount of rework to the code

@StefanTerdell
Copy link
Owner

I'm hesitant to change the structure of the code to accommodate weird bundler behavior when there's nothing wrong with it.

I'd prefer not to see these logs when building my app

Maybe there are some log level settings you can try?

Not closing the issue, mind. It's just not super high on the list of priorities ATM. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants