Code generation failure #2504

Open
opened 2026-03-13 09:59:46 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @Reco1I on GitHub (Dec 10, 2025).

Originally assigned to: @Paola3stefania on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a Nextjs 16.0.5 app
  2. Setup BetterAuth > 1.4.2
  3. Start the app

Current vs. Expected behavior

I was upgrading my BetterAuth version from 1.3.34 to 1.4.2 due to a low priority vulnerability and then I started to get this error right after running npm run dev

What version of Better Auth are you using?

1.4.2

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Enterprise",
    "release": "10.0.26100",
    "cpuCount": 20,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-12700",
    "totalMemory": "31.72 GB",
    "freeMemory": "18.42 GB"
  },
  "node": {
    "version": "v24.11.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.1"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "^16.0.7"
    },
    {
      "name": "react",
      "version": "^19.2.0"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.16.2"
    }
  ],
  "betterAuth": {
    "version": "^1.3.34",
    "config": {
      "trustedOrigins": [
        "",
        ""
      ],
      "advanced": {
        "crossSubDomainCookies": {
          "enabled": false,
          "domain": ""
        }
      },
      "emailAndPassword": {
        "enabled": true,
        "autoSignIn": false,
        "minPasswordLength": 6
      },
      "session": {
        "expiresIn": 14400,
        "updateAge": 900
      },
      "user": {
        "additionalFields": {
          "surname": {
            "type": "string",
            "required": false,
            "input": true
          },
          "firstLogin": {
            "type": "boolean",
            "required": true,
            "input": true,
            "defaultValue": true
          },
          "instituteId": {
            "type": "number",
            "required": false,
            "input": true
          },
          "roleKey": {
            "type": "string",
            "required": false,
            "input": true
          },
          "telephone": {
            "type": "string",
            "required": false,
            "input": true
          },
          "active": {
            "type": "boolean",
            "required": true,
            "input": false,
            "defaultValue": true
          }
        }
      },
      "plugins": [
        {
          "name": "custom-session",
          "config": {
            "id": "custom-session",
            "hooks": {
              "after": [
                {}
              ]
            },
            "endpoints": {},
            "$Infer": {
              "Session": {}
            }
          }
        },
        {
          "name": "admin",
          "config": {
            "id": "admin",
            "hooks": {
              "after": [
                {}
              ]
            },
            "endpoints": {},
            "$ERROR_CODES": {
              "FAILED_TO_CREATE_USER": "Failed to create user",
              "USER_ALREADY_EXISTS": "User already exists.",
              "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL": "User already exists. Use another email.",
              "YOU_CANNOT_BAN_YOURSELF": "You cannot ban yourself",
              "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE": "You are not allowed to change users role",
              "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS": "You are not allowed to create users",
              "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS": "You are not allowed to list users",
              "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS": "You are not allowed to list users sessions",
              "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS": "You are not allowed to ban users",
              "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS": "You are not allowed to impersonate users",
              "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS": "You are not allowed to revoke users sessions",
              "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS": "You are not allowed to delete users",
              "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD": "[REDACTED]",
              "BANNED_USER": "You have been banned from this application",
              "YOU_ARE_NOT_ALLOWED_TO_GET_USER": "You are not allowed to get user",
              "NO_DATA_TO_UPDATE": "No data to update",
              "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS": "You are not allowed to update users",
              "YOU_CANNOT_REMOVE_YOURSELF": "You cannot remove yourself",
              "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE": "You are not allowed to set a non-existent role value",
              "YOU_CANNOT_IMPERSONATE_ADMINS": "You cannot impersonate admins"
            },
            "schema": {
              "user": {
                "fields": {
                  "role": {
                    "type": "string",
                    "required": false,
                    "input": false
                  },
                  "banned": {
                    "type": "boolean",
                    "defaultValue": false,
                    "required": false,
                    "input": false
                  },
                  "banReason": {
                    "type": "string",
                    "required": false,
                    "input": false
                  },
                  "banExpires": {
                    "type": "date",
                    "required": false,
                    "input": false
                  }
                }
              },
              "session": {
                "fields": {
                  "impersonatedBy": {
                    "type": "string",
                    "required": false
                  }
                }
              }
            }
          }
        },
        {
          "name": "next-cookies",
          "config": {
            "id": "next-cookies",
            "hooks": {
              "after": [
                {}
              ]
            }
          }
        }
      ]
    }
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from 'better-auth'
import { prismaAdapter } from 'better-auth/adapters/prisma'
import { prisma } from '../prisma'
import { admin, customSession } from "better-auth/plugins"
import { nextCookies } from 'better-auth/next-js'


export const auth = betterAuth({
    database: prismaAdapter(prisma, {
        provider: 'sqlite',
    }),

    trustedOrigins: [
        "", 
        ""
    ],

    advanced: {
        crossSubDomainCookies: {
            enabled: process.env.NODE_ENV === 'production',
            domain: '',
        }
    },

    emailAndPassword: {
        enabled: true,
        autoSignIn: false,
        minPasswordLength: 6
    },

    session: {
        expiresIn: 60 * 60 * 4, // 4 hours
        updateAge: 60 * 15, // 15 minutes
    },

    user: {
        additionalFields: {
            surname: {
                type: 'string',
                required: false,
                input: true,
            },

            firstLogin: {
                type: 'boolean',
                required: true,
                input: true,
                defaultValue: true,
            },

            instituteId: {
                type: 'number',
                required: false,
                input: true,
            },

            roleKey: {
                type: 'string',
                required: false,
                input: true,
            },

            telephone: {
                type: 'string',
                required: false,
                input: true,
            },

            active: {
                type: 'boolean',
                required: true,
                input: false,
                defaultValue: true,
            }
        },
    },

    plugins: [
        customSession(async ({ user, session }, ctx) => {

            const dbUser = await prisma.user.findFirst({
                where: { id: user.id },
                include: {
                    roleAssigned: {
                        include: { permissions: true },
                    },
                    institute: {
                        include: { country: true },
                    }
                },
            })

            return {
                session,
                user: {
                    ...user,
                    roleAssigned: dbUser!.roleAssigned,
                    institute: dbUser!.institute,
                    instituteId: dbUser!.instituteId,
                    surname: dbUser!.surname,
                    firstLogin: dbUser!.firstLogin,
                    password: undefined,
                },
            }
        }),
        admin(),
        nextCookies()
    ]
})

Additional context

Log:

Code generation for chunk item errored
An error occurred while generating the chunk item [project]/node_modules/better-auth/dist/chunk-DieNfLhd.mjs [app-client] (ecmascript)

Caused by:
- the chunking context (unknown) does not support external modules (request: node:module)

Debug info:
- An error occurred while generating the chunk item [project]/node_modules/better-auth/dist/chunk-DieNfLhd.mjs [app-client] (ecmascript)
- Execution of <ModuleChunkItem as EcmascriptChunkItem>::content_with_async_module_info failed
- Execution of *EcmascriptChunkItemContent::new failed
- Execution of EcmascriptModuleContent::new failed
- the chunking context (unknown) does not support external modules (request: node:module)
Originally created by @Reco1I on GitHub (Dec 10, 2025). Originally assigned to: @Paola3stefania on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a Nextjs 16.0.5 app 2. Setup BetterAuth > 1.4.2 3. Start the app ### Current vs. Expected behavior I was upgrading my BetterAuth version from 1.3.34 to 1.4.2 due to a low priority vulnerability and then I started to get this error right after running `npm run dev` ### What version of Better Auth are you using? 1.4.2 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Enterprise", "release": "10.0.26100", "cpuCount": 20, "cpuModel": "12th Gen Intel(R) Core(TM) i7-12700", "totalMemory": "31.72 GB", "freeMemory": "18.42 GB" }, "node": { "version": "v24.11.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.1" }, "frameworks": [ { "name": "next", "version": "^16.0.7" }, { "name": "react", "version": "^19.2.0" } ], "databases": [ { "name": "@prisma/client", "version": "^6.16.2" } ], "betterAuth": { "version": "^1.3.34", "config": { "trustedOrigins": [ "", "" ], "advanced": { "crossSubDomainCookies": { "enabled": false, "domain": "" } }, "emailAndPassword": { "enabled": true, "autoSignIn": false, "minPasswordLength": 6 }, "session": { "expiresIn": 14400, "updateAge": 900 }, "user": { "additionalFields": { "surname": { "type": "string", "required": false, "input": true }, "firstLogin": { "type": "boolean", "required": true, "input": true, "defaultValue": true }, "instituteId": { "type": "number", "required": false, "input": true }, "roleKey": { "type": "string", "required": false, "input": true }, "telephone": { "type": "string", "required": false, "input": true }, "active": { "type": "boolean", "required": true, "input": false, "defaultValue": true } } }, "plugins": [ { "name": "custom-session", "config": { "id": "custom-session", "hooks": { "after": [ {} ] }, "endpoints": {}, "$Infer": { "Session": {} } } }, { "name": "admin", "config": { "id": "admin", "hooks": { "after": [ {} ] }, "endpoints": {}, "$ERROR_CODES": { "FAILED_TO_CREATE_USER": "Failed to create user", "USER_ALREADY_EXISTS": "User already exists.", "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL": "User already exists. Use another email.", "YOU_CANNOT_BAN_YOURSELF": "You cannot ban yourself", "YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE": "You are not allowed to change users role", "YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS": "You are not allowed to create users", "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS": "You are not allowed to list users", "YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS": "You are not allowed to list users sessions", "YOU_ARE_NOT_ALLOWED_TO_BAN_USERS": "You are not allowed to ban users", "YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS": "You are not allowed to impersonate users", "YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS": "You are not allowed to revoke users sessions", "YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS": "You are not allowed to delete users", "YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD": "[REDACTED]", "BANNED_USER": "You have been banned from this application", "YOU_ARE_NOT_ALLOWED_TO_GET_USER": "You are not allowed to get user", "NO_DATA_TO_UPDATE": "No data to update", "YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS": "You are not allowed to update users", "YOU_CANNOT_REMOVE_YOURSELF": "You cannot remove yourself", "YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE": "You are not allowed to set a non-existent role value", "YOU_CANNOT_IMPERSONATE_ADMINS": "You cannot impersonate admins" }, "schema": { "user": { "fields": { "role": { "type": "string", "required": false, "input": false }, "banned": { "type": "boolean", "defaultValue": false, "required": false, "input": false }, "banReason": { "type": "string", "required": false, "input": false }, "banExpires": { "type": "date", "required": false, "input": false } } }, "session": { "fields": { "impersonatedBy": { "type": "string", "required": false } } } } } }, { "name": "next-cookies", "config": { "id": "next-cookies", "hooks": { "after": [ {} ] } } } ] } } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth' import { prismaAdapter } from 'better-auth/adapters/prisma' import { prisma } from '../prisma' import { admin, customSession } from "better-auth/plugins" import { nextCookies } from 'better-auth/next-js' export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'sqlite', }), trustedOrigins: [ "", "" ], advanced: { crossSubDomainCookies: { enabled: process.env.NODE_ENV === 'production', domain: '', } }, emailAndPassword: { enabled: true, autoSignIn: false, minPasswordLength: 6 }, session: { expiresIn: 60 * 60 * 4, // 4 hours updateAge: 60 * 15, // 15 minutes }, user: { additionalFields: { surname: { type: 'string', required: false, input: true, }, firstLogin: { type: 'boolean', required: true, input: true, defaultValue: true, }, instituteId: { type: 'number', required: false, input: true, }, roleKey: { type: 'string', required: false, input: true, }, telephone: { type: 'string', required: false, input: true, }, active: { type: 'boolean', required: true, input: false, defaultValue: true, } }, }, plugins: [ customSession(async ({ user, session }, ctx) => { const dbUser = await prisma.user.findFirst({ where: { id: user.id }, include: { roleAssigned: { include: { permissions: true }, }, institute: { include: { country: true }, } }, }) return { session, user: { ...user, roleAssigned: dbUser!.roleAssigned, institute: dbUser!.institute, instituteId: dbUser!.instituteId, surname: dbUser!.surname, firstLogin: dbUser!.firstLogin, password: undefined, }, } }), admin(), nextCookies() ] }) ``` ### Additional context #### Log: ```log Code generation for chunk item errored An error occurred while generating the chunk item [project]/node_modules/better-auth/dist/chunk-DieNfLhd.mjs [app-client] (ecmascript) Caused by: - the chunking context (unknown) does not support external modules (request: node:module) Debug info: - An error occurred while generating the chunk item [project]/node_modules/better-auth/dist/chunk-DieNfLhd.mjs [app-client] (ecmascript) - Execution of <ModuleChunkItem as EcmascriptChunkItem>::content_with_async_module_info failed - Execution of *EcmascriptChunkItemContent::new failed - Execution of EcmascriptModuleContent::new failed - the chunking context (unknown) does not support external modules (request: node:module) ```
GiteaMirror added the nextjs label 2026-03-13 09:59:46 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 10, 2025):

Hi there, thanks for raising this issue! The error suggests that during code generation, the bundler is trying to process an external module (specifically, "node:module") which isn’t supported in the current chunking context. Here are some steps you might consider:

  1. Check your Next.js configuration to ensure that external modules are handled appropriately. You may need to adjust your webpack or Next.js configuration (for example, using resolve.alias or externals settings) so that Node’s built-in modules are properly mapped or excluded from the client bundle.

  2. Verify that your Node version and your environment support ESM imports for node: modules. Sometimes upgrading your Node version or tweaking the bundler settings to recognize “node:” prefixes can help.

  3. Since the error started appearing after upgrading Better Auth, you might try rolling back to the previous version to isolate if the change in Better Auth is a factor. If downgrading resolves it, then a compatibility update might be needed in Better Auth or your bundler configuration.

  4. Finally, review any custom plugins (like the custom session or next-cookies plugin) used in your auth config. Their interaction with your build might contribute to this issue.

I hope these steps point you toward a solution. Tag @better-auth-agent if you would like an answer from the Agent. What additional details have you noticed when troubleshooting this error?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Dec 10, 2025): Hi there, thanks for raising this issue! The error suggests that during code generation, the bundler is trying to process an external module (specifically, "node:module") which isn’t supported in the current chunking context. Here are some steps you might consider: 1. Check your Next.js configuration to ensure that external modules are handled appropriately. You may need to adjust your webpack or Next.js configuration (for example, using resolve.alias or externals settings) so that Node’s built-in modules are properly mapped or excluded from the client bundle. 2. Verify that your Node version and your environment support ESM imports for node: modules. Sometimes upgrading your Node version or tweaking the bundler settings to recognize “node:” prefixes can help. 3. Since the error started appearing after upgrading Better Auth, you might try rolling back to the previous version to isolate if the change in Better Auth is a factor. If downgrading resolves it, then a compatibility update might be needed in Better Auth or your bundler configuration. 4. Finally, review any custom plugins (like the custom session or next-cookies plugin) used in your auth config. Their interaction with your build might contribute to this issue. I hope these steps point you toward a solution. Tag @better-auth-agent if you would like an answer from the Agent. What additional details have you noticed when troubleshooting this error? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@Gbuomprisco commented on GitHub (Dec 11, 2025):

I hit the same but it turns out some server-code (in better auth) was imported into one of my client components. Try to verify all better auth imports, and make sure that you import them granularly as opposed to from the main better-auth import

@Gbuomprisco commented on GitHub (Dec 11, 2025): I hit the same but it turns out some server-code (in better auth) was imported into one of my client components. Try to verify all better auth imports, and make sure that you import them granularly as opposed to from the main `better-auth` import
Author
Owner

@SevenofThr4wn commented on GitHub (Dec 11, 2025):

I hit this issue when trying to using the 2fa client plugin import into my auth client config file, but removing that import and plugins section cleared that error

@SevenofThr4wn commented on GitHub (Dec 11, 2025): I hit this issue when trying to using the 2fa client plugin import into my auth client config file, but removing that import and plugins section cleared that error
Author
Owner

@Paola3stefania commented on GitHub (Jan 7, 2026):

@Reco1I are you still experiencing this issue?

@Paola3stefania commented on GitHub (Jan 7, 2026): @Reco1I are you still experiencing this issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2504