@better-auth/cli broken due to legacy zod import #1577

Closed
opened 2026-03-13 08:49:44 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @taylorcode on GitHub (Jul 25, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

After installing better-auth and @better-auth/cli and then running:

npx @better-auth generate

This error is printed:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports"

The error traces back to this file:
@node_modules/@better-auth/cli/dist/index.mjs

To a line that reads:

import * as z from 'zod/v4';

I believe the issue is that zod deprecated this import. When installing the @better-auth/cli on the latest version (1.3.3), the installation resolves a version of zod that no longer has this export.

I’m using pnpm, so perhaps this is related to a difference between the way npm and pnpm treat SemVer and hoist dependencies in the node_modules tree. Provided more time I would confirm this. I wanted flag this issue now in case there’s a simple fix.

Potential solutions:

  • Upgrade @better-auth/cli to zod version 4
  • Change the line in index.mjs to:
    import * as z from 'zod';

This may work unless there are other zod compatibility issues, such as a dependency on v3 features.

Current vs. Expected behavior

Expected: npx @better-auth/cli generate runs successfully as described in the setup guide
Actual: Fails with reported zod import error

What version of Better Auth are you using?

1.3.3

Provide environment information

- pnpm
- mac 15.5

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @taylorcode on GitHub (Jul 25, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce After installing `better-auth` and `@better-auth/cli` and then running: ```npx @better-auth generate``` This error is printed: ```Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports"``` The error traces back to this file: ```@node_modules/@better-auth/cli/dist/index.mjs``` To a line that reads: ``` import * as z from 'zod/v4'; ``` I believe the issue is that zod deprecated this import. When installing the `@better-auth/cli` on the latest version (`1.3.3`), the installation resolves a version of zod that no longer has this export. I’m using pnpm, so perhaps this is related to a difference between the way npm and pnpm treat SemVer and hoist dependencies in the node_modules tree. Provided more time I would confirm this. I wanted flag this issue now in case there’s a simple fix. Potential solutions: - Upgrade `@better-auth/cli` to `zod` version 4 - Change the line in index.mjs to: ```import * as z from 'zod';``` This may work unless there are other zod compatibility issues, such as a dependency on v3 features. ### Current vs. Expected behavior Expected: `npx @better-auth/cli generate` runs successfully as described in the setup guide Actual: Fails with reported zod import error ### What version of Better Auth are you using? 1.3.3 ### Provide environment information ```bash - pnpm - mac 15.5 ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:49:44 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 25, 2025):

Hi @taylorcode! I'm Dosu and I’m helping the better-auth team.

This is a known issue: the CLI still imports from 'zod/v4', which recent versions of Zod no longer export. This breaks with pnpm (and sometimes npm/yarn) when using the latest Zod, resulting in the error you described. The migration to Zod v4 in the main packages replaced all imports with 'zod/v4', but the CLI has not been updated to use the correct import path source.

There’s no official workaround documented yet. Options you can try:

  • Patch your local CLI install to change import * as z from 'zod/v4' to import * as z from 'zod' in the CLI source under node_modules (works if the rest of the code is compatible).
  • Pin Zod to an older version (e.g., zod@3.22.2 or early 4.x that still exports ./v4) as a temporary fix.
  • Use npm or yarn instead of pnpm if that avoids the error (not guaranteed).

The maintainers are aware of the Zod migration, but the CLI package specifically still uses the deprecated import path. Keep an eye out for updates to @better-auth/cli that address this.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 25, 2025): <!-- Greeting --> Hi @taylorcode! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue: the CLI still imports from `'zod/v4'`, which recent versions of Zod no longer export. This breaks with pnpm (and sometimes npm/yarn) when using the latest Zod, resulting in the error you described. The migration to Zod v4 in the main packages replaced all imports with `'zod/v4'`, but the CLI has not been updated to use the correct import path [`source`](https://github.com/better-auth/better-auth/blob/f99305b29eb096186a0f85100e01f721d208f2f0/packages/cli/src/commands/generate.ts). There’s no official workaround documented yet. Options you can try: - Patch your local CLI install to change `import * as z from 'zod/v4'` to `import * as z from 'zod'` in the CLI source under `node_modules` (works if the rest of the code is compatible). - Pin Zod to an older version (e.g., `zod@3.22.2` or early `4.x` that still exports `./v4`) as a temporary fix. - Use npm or yarn instead of pnpm if that avoids the error (not guaranteed). The maintainers are aware of the Zod migration, but the CLI package specifically still uses the deprecated import path. Keep an eye out for updates to `@better-auth/cli` that address this. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7d956681-c7b4-4dd6-b406-be6499518396?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3614)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1577