Giter Site home page Giter Site logo

Comments (22)

colinhacks avatar colinhacks commented on July 25, 2024 2

Thanks for the quick action @juliusmarminge.

I've fixed the underlying problem in Zod 3.23.2, so there's no need for everyone to upgrade. Perhaps add this as a note at the top of the original issue to avoid further confusion?


Notes for those who are so inclined:

Because createEnv in t3env/next lacks an explicit return type annotation, TypeScript generates one for the .d.ts. To do so, it pulls in some internal Zod utilities (namely objectUtil.addQuestionMarks) from whatever version of Zod was installed when the build happened. You can see this in this snippet of the declaration file:

declare function createEnv<
	TServer extends Record<string, ZodType> = NonNullable<unknown>,
	TClient extends Record<
		`${ClientPrefix}${string}`,
		ZodType
	> = NonNullable<unknown>,
	TShared extends Record<string, ZodType> = NonNullable<unknown>,
	const TExtends extends Array<Record<string, unknown>> = [],
>(
	opts: Options<TServer, TClient, TShared, TExtends>,
): Readonly<
	(zod.objectUtil.addQuestionMarks<
		zod.baseObjectOutputType<TServer>,
		{
			[k_1 in keyof zod.baseObjectOutputType<TServer>]: undefined extends zod.baseObjectOutputType<TServer>[k_1]
				? never
				: k_1;
		}[keyof TServer]
	> extends infer T_25
		? {
				[k in keyof T_25]: zod.objectUtil.addQuestionMarks<
					zod.baseObjectOutputType<TServer>,
					{
						[k_1 in keyof zod.baseObjectOutputType<TServer>]: undefined extends zod.baseObjectOutputType<TServer>[k_1]
							? never
							: k_1;
					}[keyof TServer]
				>[k];
			}
		: never) 
		// ...
 >	

This essentially means that that dependency on Zod is no longer "portable" and requires a specific version of Zod to work properly.

Normally compiling something like this with tsc would throw an error like the one below. I'm currently seeing this error for the nuxt package but not the nextjs one when building the packages locally 🤷‍♂️ I'm still not sure why.

@t3-oss/env-nuxt:build: src/index.ts(19,17): error TS2742: The inferred type of 'createEnv' cannot be named without a reference to '@t3-oss/env-core/node_modules/.pnpm/[email protected]/node_modules/zod'. This is likely not portable. A type annotation is necessary.

The utility type zod.objectUtil.addQuestionMarks changed from accepting two generics to accepting a single generic. Because the 3.22.x version of this utility had leaked into the declaration file for [email protected], the typings for t3-env broke when used in conjunction with [email protected].

My fix was to add a second generic argument back to that type (a no-op): colinhacks/zod@ef588d0

I think an explicity return type on createEnv would future-proof the library. I made a PR to that effect: #224

I'll also see if there's something I can do on my size to prevent Zod utilities from getting "inlined" like this in the future.


Unrelated, there's also some kind of recursive unrollling happening due to Reduce<> that blows up the index.d.ts file. This is also fixed by my PR. (But it's unrelated to this issue.)

from t3-env.

ArekBartnik avatar ArekBartnik commented on July 25, 2024 2

@t3-oss/env-nextjs: 0.9.1 with zod: 3.23.4 (latest) -> works
@t3-oss/env-nextjs: 0.10.1 (latest) with zod: 3.23.4 (latest) -> shows any

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024 1

Though there is a breaking change on presets, which are now functions

Yea this will be a 0.10 release. Needed to make them functions to avoid side-effects in the imports

I'll go ahead and relese 0.10 now then

from t3-env.

vaun-blu avatar vaun-blu commented on July 25, 2024 1

3-oss/env-nextjs: 0.9.1

I also get this issue. Reverting to 0.9.1 fixes the issue for now

from t3-env.

Stewart86 avatar Stewart86 commented on July 25, 2024

Same, just got a failed check with dependabot for Zod version bump. Following for resolution.

from t3-env.

waltershewmake avatar waltershewmake commented on July 25, 2024

Also experiencing this

from t3-env.

shadizx avatar shadizx commented on July 25, 2024

same, but i'm experiencing this with older zod versions as well.

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

Someone know what types they've changed? We're not using any internal types so feels like they've unintentionally broken semver.

same, but i'm experiencing this with older zod versions as well.

That's weird, please open a separate issue with a reproduction.

from t3-env.

mwskwong avatar mwskwong commented on July 25, 2024

@juliusmarminge Could it be related to this change?
image

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

@juliusmarminge Could it be related to this change? image

we're only using ZodType as a generic constraint so that shouldn't matter

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

can't reproduce inside this repo though which will make it harder to debug...
CleanShot 2024-04-22 at 10 08 42@2x

from t3-env.

mwskwong avatar mwskwong commented on July 25, 2024

can't reproduce inside this repo though which will make it harder to debug... CleanShot 2024-04-22 at 10 08 42@2x

Interesting. Since there have been a few commits since the last release, maybe one of the commits "solves" unintentionally (e.g. the "bump deps" one, which is doing more than just bumping deps)?

Is it feasible to release a beta/canary/unstable release so that we can test it and see whether that's the case?

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

Is it feasible to release a beta/canary/unstable release so that we can test it and see whether that's the case?

Was just about to do that from #223

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

Try this one: pnpm add @t3-oss/[email protected]

from t3-env.

Stewart86 avatar Stewart86 commented on July 25, 2024

yup looks like canary fixes it for me

from t3-env.

mwskwong avatar mwskwong commented on July 25, 2024

Same for me.

Though there is a breaking change on presets, which are now functions

from t3-env.

ixuz avatar ixuz commented on July 25, 2024

Still a problem for me.

Using: @t3-oss/env-nextjs: 0.10.1 with zod: 3.23.8 and the createEnv returns any type.

from t3-env.

bastibuck avatar bastibuck commented on July 25, 2024

@juliusmarminge I can confirm this issue still persists like described above. Rolling back to 0.9.1 works for now

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

If anyone still gets this please also provide a reproduction. Im using the latest version without issues

from t3-env.

bastibuck avatar bastibuck commented on July 25, 2024

When I install 0.10.1 it says

Cannot find module '@t3-oss/env-nextjs' or its corresponding type declarations.

Using version 0.9.1 it works fine.

See https://codesandbox.io/p/devbox/dreamy-black-7l4ywn?workspaceId=78150bbe-056c-4c8d-8542-1698ecfb6c1d

from t3-env.

juliusmarminge avatar juliusmarminge commented on July 25, 2024

When I install 0.10.1 it says

Cannot find module '@t3-oss/env-nextjs' or its corresponding type declarations.

Using version 0.9.1 it works fine.

See https://codesandbox.io/p/devbox/dreamy-black-7l4ywn?workspaceId=78150bbe-056c-4c8d-8542-1698ecfb6c1d

You're using an incompatible module resolution. See https://github.com/t3-oss/t3-env#installation for compatible options

CleanShot 2024-05-30 at 13 57 43@2x

from t3-env.

bastibuck avatar bastibuck commented on July 25, 2024

Ahhh I see. After I changed it to

    "moduleResolution": "Bundler",
    "module": "esnext",

it seems to work.

Also I had to use proper import instead of require inside my next.config.mjs. Maybe this helps anyone else finding this

from t3-env.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.