[GH-ISSUE #766] Type errors when using better-auth in next-forge #17049

Closed
opened 2026-04-15 14:59:39 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @trevorpfiz on GitHub (Dec 4, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/766

Describe the bug
Type errors when using better-auth in next-forge

The inferred type of 'auth' cannot be named without a reference to '.pnpm/better-call@0.3.3-beta.4/node_modules/better-call'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.ts(7056)
The inferred type of 'signIn' cannot be named without a reference to '.pnpm/@better-fetch+fetch@1.1.12/node_modules/@better-fetch/fetch'. This is likely not portable. A type annotation is necessary.ts(2742)

To Reproduce
Steps to reproduce the behavior:

  1. Start project with next-forge
  2. Follow guide to switch to better-auth
  3. I also followed switch to drizzle
  4. See error

Expected behavior
I would expect there to be no type errors.

Screenshots
image
image
image

Additional context
This is a related discussion https://github.com/trpc/trpc/discussions/5636

Originally created by @trevorpfiz on GitHub (Dec 4, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/766 **Describe the bug** Type errors when using `better-auth` in `next-forge` `The inferred type of 'auth' cannot be named without a reference to '.pnpm/better-call@0.3.3-beta.4/node_modules/better-call'. This is likely not portable. A type annotation is necessary.ts(2742)` `The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.ts(7056)` `The inferred type of 'signIn' cannot be named without a reference to '.pnpm/@better-fetch+fetch@1.1.12/node_modules/@better-fetch/fetch'. This is likely not portable. A type annotation is necessary.ts(2742)` **To Reproduce** Steps to reproduce the behavior: 1. Start project with [next-forge](https://www.next-forge.com/) 2. Follow [guide](https://docs.next-forge.com/authentication/better-auth) to switch to `better-auth` 3. I also followed [switch to drizzle](https://docs.next-forge.com/database/drizzle) 4. See error **Expected behavior** I would expect there to be no type errors. **Screenshots** ![image](https://github.com/user-attachments/assets/781825c6-5c8f-43fc-9ced-72f5063f15df) ![image](https://github.com/user-attachments/assets/128a0635-120d-48ff-bfc8-b9cc93c823ff) ![image](https://github.com/user-attachments/assets/30c544bf-cfe8-4370-b8cc-aadcfe1baad3) **Additional context** This is a related discussion https://github.com/trpc/trpc/discussions/5636
GiteaMirror added the locked label 2026-04-15 14:59:39 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 5, 2024):

does this happen after you have disabled declaration?

<!-- gh-comment-id:2519514723 --> @Bekacru commented on GitHub (Dec 5, 2024): does this happen after you have disabled `declaration`?
Author
Owner

@SkidGod4444 commented on GitHub (Dec 5, 2024):

amed without a reference

this type of things only happens on some IDE

<!-- gh-comment-id:2521249532 --> @SkidGod4444 commented on GitHub (Dec 5, 2024): > amed without a reference this type of things only happens on some IDE
Author
Owner

@trevorpfiz commented on GitHub (Dec 5, 2024):

does this happen after you have disabled declaration?

the error goes away with:

"declaration": false,
"declarationMap": false
<!-- gh-comment-id:2521277295 --> @trevorpfiz commented on GitHub (Dec 5, 2024): > does this happen after you have disabled `declaration`? the error goes away with: ``` "declaration": false, "declarationMap": false ```
Author
Owner

@catnaut commented on GitHub (Dec 7, 2024):

I encountered this issue while using better-auth/vue:

import { createAuthClient } from 'better-auth/vue'

export const authClient = createAuthClient({
  baseURL: 'http://localhost:5173', // the base url of your auth server
})

Error:

The inferred type of 'authClient' cannot be named without a reference to '.pnpm/@better-fetch+fetch@1.1.12/node_modules/@better-fetch/fetch'. This is likely not portable. A type annotation is necessary. ts(2742)
The inferred type of 'authClient' cannot be named without a reference to '.pnpm/nanostores@0.11.3/node_modules/nanostores'. This is likely not portable. A type annotation is necessary. ts(2742)
The type of this node cannot be serialized because its property '[iterator]' cannot be serialized. ts(4118)
The type of this node cannot be serialized because its property '[unscopables]' cannot be serialized. ts(4118)
<!-- gh-comment-id:2525241166 --> @catnaut commented on GitHub (Dec 7, 2024): I encountered this issue while using `better-auth/vue`: ```ts import { createAuthClient } from 'better-auth/vue' export const authClient = createAuthClient({ baseURL: 'http://localhost:5173', // the base url of your auth server }) ``` **Error:** ``` The inferred type of 'authClient' cannot be named without a reference to '.pnpm/@better-fetch+fetch@1.1.12/node_modules/@better-fetch/fetch'. This is likely not portable. A type annotation is necessary. ts(2742) The inferred type of 'authClient' cannot be named without a reference to '.pnpm/nanostores@0.11.3/node_modules/nanostores'. This is likely not portable. A type annotation is necessary. ts(2742) The type of this node cannot be serialized because its property '[iterator]' cannot be serialized. ts(4118) The type of this node cannot be serialized because its property '[unscopables]' cannot be serialized. ts(4118) ```
Author
Owner

@Bekacru commented on GitHub (Dec 8, 2024):

I encountered this issue while using better-auth/vue:

same. make sure to set declaration:false and strict:true

<!-- gh-comment-id:2525440769 --> @Bekacru commented on GitHub (Dec 8, 2024): > I encountered this issue while using `better-auth/vue`: same. make sure to set `declaration:false` and `strict:true`
Author
Owner

@Bekacru commented on GitHub (Dec 8, 2024):

I'm gonna close this. This is already referenced in the docs https://www.better-auth.com/docs/concepts/typescript

feel free to open another issue if you're facing a related problem with ts.

<!-- gh-comment-id:2525441077 --> @Bekacru commented on GitHub (Dec 8, 2024): I'm gonna close this. This is already referenced in the docs https://www.better-auth.com/docs/concepts/typescript feel free to open another issue if you're facing a related problem with ts.
Author
Owner

@natew commented on GitHub (Dec 20, 2024):

@Bekacru we have a build library that uses declarations only, having to work around this is causing us to have only one package in our repo be different. How hard would it be to allow this?

CleanShot 2024-12-19 at 14 16 41@2x

<!-- gh-comment-id:2556000363 --> @natew commented on GitHub (Dec 20, 2024): @Bekacru we have a build library that uses declarations only, having to work around this is causing us to have only one package in our repo be different. How hard would it be to allow this? ![CleanShot 2024-12-19 at 14 16 41@2x](https://github.com/user-attachments/assets/dfcd61ee-27a7-4427-86ca-0a41e8fa4990)
Author
Owner

@Bekacru commented on GitHub (Dec 20, 2024):

@Bekacru we have a build library that uses declarations only, having to work around this is causing us to have only one package in our repo be different. How hard would it be to allow this?

just went through some issues and I think I found the issue. Could you try 1.0.23-beta.5 and see if it fixes it? The server auth instance may still have a problem, but the authClient should likely be fixed.

<!-- gh-comment-id:2556736492 --> @Bekacru commented on GitHub (Dec 20, 2024): > @Bekacru we have a build library that uses declarations only, having to work around this is causing us to have only one package in our repo be different. How hard would it be to allow this? just went through some issues and I think I found the issue. Could you try `1.0.23-beta.5` and see if it fixes it? The server `auth` instance may still have a problem, but the `authClient` should likely be fixed.
Author
Owner

@ISnackable commented on GitHub (Dec 21, 2024):

I tried installing 1.0.23-beta.6 but I am still having this issue. While setting declaration: false in tsconfig.json does "solve" the issue on the IDE side, when you try building the app this error still persists.

 > next build
│ 
│    ▲ Next.js 15.1.2
│    - Environments: .env
│    - Experiments (use with caution):
│      · reactCompiler
│ 
│    Creating an optimized production build ...
│  ✓ Compiled successfully
│    Linting and checking validity of types  ..Failed to compile.
│ 
│ ../../packages/auth/client.ts:9:14
│ Type error: The inferred type of 'client' cannot be named without a reference to '.pnpm/@si
│ mplewebauthn+types@10.0.0/node_modules/@simplewebauthn/types'. This is likely not portable.
│  A type annotation is necessary.
│ 
│    7 | import { createAuthClient } from 'better-auth/react';
│    8 |
│ >  9 | export const client = createAuthClient({
│      |              ^
│   10 |   baseURL: host, // the base url of your auth server
│   11 |   plugins: [organizationClient(), passkeyClient(), multiSessionClient()],
│   12 | });
│  ELIFECYCLE  Command failed with exit code 1.
│ command finished with error: command (/workspaces/next-forge/apps/app) /usr/local/share/npm-g
│ lobal/bin/pnpm run build exited (1)
└────>
app#build: command (/workspaces/next-forge/apps/app) /usr/local/share/npm-global/bin/pnpm run build exited (1)

Wondering if there's any workaround like manually typing the client?

Edit: Nvm, you also need to add declaration: false in the nextjs apps tsconfig. However, I hope this is eventually fixed...

<!-- gh-comment-id:2558110178 --> @ISnackable commented on GitHub (Dec 21, 2024): I tried installing `1.0.23-beta.6` but I am still having this issue. While setting `declaration: false` in tsconfig.json does "solve" the issue on the IDE side, when you try building the app this error still persists. ```bash > next build │ │ ▲ Next.js 15.1.2 │ - Environments: .env │ - Experiments (use with caution): │ · reactCompiler │ │ Creating an optimized production build ... │ ✓ Compiled successfully │ Linting and checking validity of types ..Failed to compile. │ │ ../../packages/auth/client.ts:9:14 │ Type error: The inferred type of 'client' cannot be named without a reference to '.pnpm/@si │ mplewebauthn+types@10.0.0/node_modules/@simplewebauthn/types'. This is likely not portable. │ A type annotation is necessary. │ │ 7 | import { createAuthClient } from 'better-auth/react'; │ 8 | │ > 9 | export const client = createAuthClient({ │ | ^ │ 10 | baseURL: host, // the base url of your auth server │ 11 | plugins: [organizationClient(), passkeyClient(), multiSessionClient()], │ 12 | }); │  ELIFECYCLE  Command failed with exit code 1. │ command finished with error: command (/workspaces/next-forge/apps/app) /usr/local/share/npm-g │ lobal/bin/pnpm run build exited (1) └────> app#build: command (/workspaces/next-forge/apps/app) /usr/local/share/npm-global/bin/pnpm run build exited (1) ``` Wondering if there's any workaround like manually typing the client? Edit: Nvm, you also need to add `declaration: false` in the nextjs apps tsconfig. However, I hope this is eventually fixed...
Author
Owner

@luskin commented on GitHub (Dec 29, 2024):

For what it's worth, this issue only exists for us when adding the passkey plugin to the plugins array. Removing that plugin produces no typescript errors.

<!-- gh-comment-id:2564865416 --> @luskin commented on GitHub (Dec 29, 2024): For what it's worth, this issue only exists for us when adding the `passkey` plugin to the plugins array. Removing that plugin produces no typescript errors.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17049