[GH-ISSUE #3352] bug: Cannot find package 'uncrypto' when using with Nuxt 3 #9576

Closed
opened 2026-04-13 05:06:11 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @aveliino88 on GitHub (Jul 12, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3352

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

OS: Windows 10 (win32 10.0.19045)
Bun Version: 1.2.18
Nuxt Version: 3.17.6
better-auth Version: 1.2.12
@better-auth/utils Version: 0.2.6
uncrypto Version: 0.1.3

Current vs. Expected behavior

[request error] [unhandled] [GET] http://localhost:3000/api/auth/get-session
903 | unhandled = false;
904 | statusMessage;
905 | data;
906 | cause;
907 | constructor(message, opts = {}) {
908 | super(message, opts);
^
error: Cannot find package 'uncrypto' from 'C:\Git\nuxtbaseapp.output\server\node_modules@better-auth\utils\dist\index.mjs'
cause: error: Cannot find package 'uncrypto' from 'C:\Git\nuxtbaseapp.output\server\node_modules@better-auth\utils\dist\index.mjs',
statusCode: 500,
fatal: false,
unhandled: true,
statusMessage: undefined,
data: undefined,

  at new H3Error (C:\Git\nuxtbaseapp\.output\server\chunks\_\nitro.mjs:908:5)
  at createError$1 (C:\Git\nuxtbaseapp\.output\server\chunks\_\nitro.mjs:934:15)
  at <anonymous> (C:\Git\nuxtbaseapp\.output\server\chunks\_\nitro.mjs:2259:21)

What version of Better Auth are you using?

1.2.12

Provide environment information

When running a Nuxt 3 application that uses better-auth in a production-like environment (after running nuxt build), server-side requests to authentication endpoints fail with the error: Cannot find package 'uncrypto' from '...\\.output\\server\\node_modules\\@better-auth\\utils\\dist\\index.mjs'.
This issue seems to be specific to the interaction between Nuxt/Nitro's bundling and how @better-auth/utils resolves the uncrypto dependency, particularly on Windows. The project is configured to inline uncrypto in the nitro config, which is a standard workaround for similar issues, but it doesn't seem to solve the problem in this case.

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../lib/database";

export function createAuth(config: any) {
  return betterAuth({
    database: drizzleAdapter(db, { provider: "pg" }),
    emailAndPassword: { enabled: false },
    socialProviders: {
      github: {
        clientId: config.githubClientId || "",
        clientSecret: config.githubClientSecret || "",
      },
      google: {
        prompt: "select_account",
        clientId: config.googleClientId || "",
        clientSecret: config.googleClientSecret || "",
      },
    },
    redirect: {
      afterSignIn: "/dashboard",
      afterSignUp: "/dashboard",
      afterRequestPassword: "/dashboard",
      afterResetPassword: "/dashboard",
      afterVerifyEmail: "/",
      afterUpdateEmail: "/",
    },
  });
}

// For backward compatibility, create a default instance
const defaultConfig = {
  githubClientId: process.env.GITHUB_CLIENT_ID,
  githubClientSecret: process.env.GITHUB_CLIENT_SECRET,
  googleClientId: process.env.GOOGLE_CLIENT_ID,
  googleClientSecret: process.env.GOOGLE_CLIENT_SECRET,
};

export const auth = createAuth(defaultConfig);

Additional context

IMPORTANT it works as it should in dev mode ( bun run dev) however doesn't work in bun run start (production)
I tried it locally and docker and it fails.

Originally created by @aveliino88 on GitHub (Jul 12, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3352 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce OS: Windows 10 (win32 10.0.19045) Bun Version: 1.2.18 Nuxt Version: 3.17.6 better-auth Version: 1.2.12 @better-auth/utils Version: 0.2.6 uncrypto Version: 0.1.3 ### Current vs. Expected behavior [request error] [unhandled] [GET] http://localhost:3000/api/auth/get-session 903 | unhandled = false; 904 | statusMessage; 905 | data; 906 | cause; 907 | constructor(message, opts = {}) { 908 | super(message, opts); ^ error: Cannot find package 'uncrypto' from 'C:\Git\nuxtbaseapp\.output\server\node_modules\@better-auth\utils\dist\index.mjs' cause: error: Cannot find package 'uncrypto' from 'C:\Git\nuxtbaseapp\.output\server\node_modules\@better-auth\utils\dist\index.mjs', statusCode: 500, fatal: false, unhandled: true, statusMessage: undefined, data: undefined, at new H3Error (C:\Git\nuxtbaseapp\.output\server\chunks\_\nitro.mjs:908:5) at createError$1 (C:\Git\nuxtbaseapp\.output\server\chunks\_\nitro.mjs:934:15) at <anonymous> (C:\Git\nuxtbaseapp\.output\server\chunks\_\nitro.mjs:2259:21) ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash When running a Nuxt 3 application that uses better-auth in a production-like environment (after running nuxt build), server-side requests to authentication endpoints fail with the error: Cannot find package 'uncrypto' from '...\\.output\\server\\node_modules\\@better-auth\\utils\\dist\\index.mjs'. This issue seems to be specific to the interaction between Nuxt/Nitro's bundling and how @better-auth/utils resolves the uncrypto dependency, particularly on Windows. The project is configured to inline uncrypto in the nitro config, which is a standard workaround for similar issues, but it doesn't seem to solve the problem in this case. ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "../lib/database"; export function createAuth(config: any) { return betterAuth({ database: drizzleAdapter(db, { provider: "pg" }), emailAndPassword: { enabled: false }, socialProviders: { github: { clientId: config.githubClientId || "", clientSecret: config.githubClientSecret || "", }, google: { prompt: "select_account", clientId: config.googleClientId || "", clientSecret: config.googleClientSecret || "", }, }, redirect: { afterSignIn: "/dashboard", afterSignUp: "/dashboard", afterRequestPassword: "/dashboard", afterResetPassword: "/dashboard", afterVerifyEmail: "/", afterUpdateEmail: "/", }, }); } // For backward compatibility, create a default instance const defaultConfig = { githubClientId: process.env.GITHUB_CLIENT_ID, githubClientSecret: process.env.GITHUB_CLIENT_SECRET, googleClientId: process.env.GOOGLE_CLIENT_ID, googleClientSecret: process.env.GOOGLE_CLIENT_SECRET, }; export const auth = createAuth(defaultConfig); ``` ### Additional context IMPORTANT it works as it should in dev mode ( bun run dev) however doesn't work in bun run start (production) I tried it locally and docker and it fails.
GiteaMirror added the lockedbug labels 2026-04-13 05:06:11 -05:00
Author
Owner

@aveliino88 commented on GitHub (Jul 12, 2025):

`FROM oven/bun:1-alpine

WORKDIR /app

COPY . .

RUN bun install --frozen-lockfile --verbose

RUN bun list | grep -E "(uncrypto|crypto|@peculiar)" || echo "No crypto packages found"

RUN ls -la lib/ && echo "=== Lib directory contents ==="
RUN ls -la server/ && echo "=== Server directory contents ==="

RUN bun run db:generate

RUN bun run build

RUN mkdir -p .output/server/node_modules/uncrypto
RUN cp -r node_modules/uncrypto/* .output/server/node_modules/uncrypto/

RUN apk add --no-cache curl

EXPOSE 3000

ENV NODE_ENV=production

RUN cp -r public .output/public

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3
CMD curl -f http://localhost:3000/api/health || exit 1

CMD ["bun", ".output/server/index.mjs"] `

I managed to get it working in production by
RUN mkdir -p .output/server/node_modules/uncrypto
RUN cp -r node_modules/uncrypto/* .output/server/node_modules/uncrypto/ doing this ,however this is not a proper solution. I am not sure is it me doing something wrong or is there a problem somewhere in Nuxt/Nitro or better-auth

<!-- gh-comment-id:3064870986 --> @aveliino88 commented on GitHub (Jul 12, 2025): `FROM oven/bun:1-alpine WORKDIR /app COPY . . RUN bun install --frozen-lockfile --verbose RUN bun list | grep -E "(uncrypto|crypto|@peculiar)" || echo "No crypto packages found" RUN ls -la lib/ && echo "=== Lib directory contents ===" RUN ls -la server/ && echo "=== Server directory contents ===" RUN bun run db:generate RUN bun run build RUN mkdir -p .output/server/node_modules/uncrypto RUN cp -r node_modules/uncrypto/* .output/server/node_modules/uncrypto/ RUN apk add --no-cache curl EXPOSE 3000 ENV NODE_ENV=production RUN cp -r public .output/public HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:3000/api/health || exit 1 CMD ["bun", ".output/server/index.mjs"] ` I managed to get it working in production by RUN mkdir -p .output/server/node_modules/uncrypto RUN cp -r node_modules/uncrypto/* .output/server/node_modules/uncrypto/ doing this ,however this is not a proper solution. I am not sure is it me doing something wrong or is there a problem somewhere in Nuxt/Nitro or better-auth
Author
Owner

@NicoToff commented on GitHub (Jul 15, 2025):

Hey there.
Does this happen with node.js, too? Or deno, if you're allergic to node.
Also, is uncrypto in your deps or is it internal to better-auth?

<!-- gh-comment-id:3072029146 --> @NicoToff commented on GitHub (Jul 15, 2025): Hey there. Does this happen with `node.js`, too? Or `deno`, if you're allergic to node. Also, is `uncrypto` in your deps or is it internal to `better-auth`?
Author
Owner

@aveliino88 commented on GitHub (Jul 15, 2025):

Hey there. Does this happen with node.js, too? Or deno, if you're allergic to node. Also, is uncrypto in your deps or is it internal to better-auth?

I tried node and bun. Also installed uncrypto as direct dependency and it didn't help. in DEV it worked OKEY however in production it all got weird.

<!-- gh-comment-id:3072800931 --> @aveliino88 commented on GitHub (Jul 15, 2025): > Hey there. Does this happen with `node.js`, too? Or `deno`, if you're allergic to node. Also, is `uncrypto` in your deps or is it internal to `better-auth`? I tried node and bun. Also installed uncrypto as direct dependency and it didn't help. in DEV it worked OKEY however in production it all got weird.
Author
Owner

@Kinfe123 commented on GitHub (Jul 21, 2025):

Have you tried it with latest version of node ?

<!-- gh-comment-id:3097189745 --> @Kinfe123 commented on GitHub (Jul 21, 2025): Have you tried it with latest version of node ?
Author
Owner

@Kinfe123 commented on GitHub (Aug 11, 2025):

Closing now since i cant reproduce this. if you think this is an issue needs to be addressed. tag me with repro, happy to take a look at it.

<!-- gh-comment-id:3176882458 --> @Kinfe123 commented on GitHub (Aug 11, 2025): Closing now since i cant reproduce this. if you think this is an issue needs to be addressed. tag me with repro, happy to take a look at it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9576