[GH-ISSUE #8620] require() of ES Module /var/task/node_modules/camelcase/index.js #11140

Open
opened 2026-04-13 07:30:27 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @SleeveShirtholes on GitHub (Mar 15, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8620

Originally assigned to: @jonathansamines on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Follow the instructions to add the new better-auth/infra package to a project using tanstack start and deploy on Netlify

Current vs. Expected behavior

After following the directions to add the new @better-auth/infra package and deploying a tanstack start application to Netlify, I get the following error when trying to load the site:

Error - require() of ES Module /var/task/node_modules/camelcase/index.js from /var/task/node_modules/samlify/build/src/extractor.js not supported. Instead change the require of index.js in /var/task/node_modules/samlify/build/src/extractor.js to a dynamic import() which is available in all CommonJS modules.

Stack Trace

Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/camelcase/index.js from /var/task/node_modules/samlify/build/src/extractor.js not supported.
Instead change the require of index.js in /var/task/node_modules/samlify/build/src/extractor.js to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:328:14)
at Object. (/var/task/node_modules/samlify/build/src/extractor.js:29:35)

What version of Better Auth are you using?

1.5.5

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:08:48 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8132",
    "release": "25.2.0",
    "cpuCount": 10,
    "cpuModel": "Apple M4",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.35 GB"
  },
  "node": {
    "version": "v22.17.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.4.2"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^19.2.0"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "@prisma/client",
      "version": "^7.2.0"
    }
  ],
  "betterAuth": {
    "version": "Unknown",
    "config": null,
    "error": "Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth."
  }
}

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

Client

Auth config (if applicable)

import { prisma } from '@/db'
import { betterAuth } from 'better-auth'
import { prismaAdapter } from 'better-auth/adapters/prisma'
import { magicLink } from 'better-auth/plugins'
import { tanstackStartCookies } from 'better-auth/tanstack-start'
import { sendMagicLinkEmail } from './email-templates'

// Helper function to get environment variables with proper fallback
function getEnvVar(key: string): string {
  // Try process.env directly first (works in Netlify serverless functions)
  if (process.env?.[key]) {
    return process.env[key]!
  }
  
  // Try Cloudflare Workers env (for other deployments)
  if (typeof globalThis !== 'undefined' && (globalThis as any).env?.[key]) {
    return (globalThis as any).env[key]
  }
  
  // Try globalThis.process.env (fallback)
  if (typeof globalThis !== 'undefined' && globalThis.process?.env?.[key]) {
    return globalThis.process.env[key]!
  }
  
  throw new Error(`Environment variable ${key} is not set`)
}

// Configure better-auth
export const auth = betterAuth({
  baseURL: getEnvVar('BETTER_AUTH_URL'),
  secret: getEnvVar('BETTER_AUTH_SECRET'),
  socialProviders: {
    google: {
      clientId: getEnvVar('GOOGLE_CLIENT_ID'),
      clientSecret: getEnvVar('GOOGLE_CLIENT_SECRET'),
    },
  },
  database: prismaAdapter(prisma, {
    provider: 'postgresql',
  }),
  trustedOrigins: [
    'https://winlosstracker.com',
    'https://www.winlosstracker.com',
    'http://localhost:3000', // for local development
    'https://winloss-tracker.netlify.app', // for preview deployments
    'https://.*--winloss-tracker\\.netlify\\.app', // for dynamic deploy previews
  ],
  plugins: [
    tanstackStartCookies(),
    magicLink({
      // Required: Function to send magic link email
      async sendMagicLink({ email, url }) {
        return await sendMagicLinkEmail({ email, url })
      },
      // Optional: Set token expiration (default: 300 seconds / 5 minutes)
      expiresIn: 300,
      // Optional: Disable sign up via magic link (default: false)
      disableSignUp: false,
    }),
  ],
})

Additional context

Better Auth works just fine without adding the new package.

Originally created by @SleeveShirtholes on GitHub (Mar 15, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8620 Originally assigned to: @jonathansamines on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Follow the instructions to add the new better-auth/infra package to a project using tanstack start and deploy on Netlify ### Current vs. Expected behavior After following the directions to add the new @better-auth/infra package and deploying a tanstack start application to Netlify, I get the following error when trying to load the site: Error - require() of ES Module /var/task/node_modules/camelcase/index.js from /var/task/node_modules/samlify/build/src/extractor.js not supported. Instead change the require of index.js in /var/task/node_modules/samlify/build/src/extractor.js to a dynamic import() which is available in all CommonJS modules. Stack Trace Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/camelcase/index.js from /var/task/node_modules/samlify/build/src/extractor.js not supported. Instead change the require of index.js in /var/task/node_modules/samlify/build/src/extractor.js to a dynamic import() which is available in all CommonJS modules. at TracingChannel.traceSync (node:diagnostics_channel:328:14) at Object.<anonymous> (/var/task/node_modules/samlify/build/src/extractor.js:29:35) ### What version of Better Auth are you using? 1.5.5 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:08:48 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8132", "release": "25.2.0", "cpuCount": 10, "cpuModel": "Apple M4", "totalMemory": "16.00 GB", "freeMemory": "0.35 GB" }, "node": { "version": "v22.17.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.4.2" }, "frameworks": [ { "name": "react", "version": "^19.2.0" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "@prisma/client", "version": "^7.2.0" } ], "betterAuth": { "version": "Unknown", "config": null, "error": "Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth." } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { prisma } from '@/db' import { betterAuth } from 'better-auth' import { prismaAdapter } from 'better-auth/adapters/prisma' import { magicLink } from 'better-auth/plugins' import { tanstackStartCookies } from 'better-auth/tanstack-start' import { sendMagicLinkEmail } from './email-templates' // Helper function to get environment variables with proper fallback function getEnvVar(key: string): string { // Try process.env directly first (works in Netlify serverless functions) if (process.env?.[key]) { return process.env[key]! } // Try Cloudflare Workers env (for other deployments) if (typeof globalThis !== 'undefined' && (globalThis as any).env?.[key]) { return (globalThis as any).env[key] } // Try globalThis.process.env (fallback) if (typeof globalThis !== 'undefined' && globalThis.process?.env?.[key]) { return globalThis.process.env[key]! } throw new Error(`Environment variable ${key} is not set`) } // Configure better-auth export const auth = betterAuth({ baseURL: getEnvVar('BETTER_AUTH_URL'), secret: getEnvVar('BETTER_AUTH_SECRET'), socialProviders: { google: { clientId: getEnvVar('GOOGLE_CLIENT_ID'), clientSecret: getEnvVar('GOOGLE_CLIENT_SECRET'), }, }, database: prismaAdapter(prisma, { provider: 'postgresql', }), trustedOrigins: [ 'https://winlosstracker.com', 'https://www.winlosstracker.com', 'http://localhost:3000', // for local development 'https://winloss-tracker.netlify.app', // for preview deployments 'https://.*--winloss-tracker\\.netlify\\.app', // for dynamic deploy previews ], plugins: [ tanstackStartCookies(), magicLink({ // Required: Function to send magic link email async sendMagicLink({ email, url }) { return await sendMagicLinkEmail({ email, url }) }, // Optional: Set token expiration (default: 300 seconds / 5 minutes) expiresIn: 300, // Optional: Disable sign up via magic link (default: false) disableSignUp: false, }), ], }) ``` ### Additional context Better Auth works just fine without adding the new package.
GiteaMirror added the platformbug labels 2026-04-13 07:30:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 15, 2026):

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

This is a known issue with the @better-auth/infra package. The package has a critical CommonJS compatibility bug due to its package.json exports using the "import" condition instead of "default", which breaks serverless deployments like Netlify.

The maintainers acknowledged this issue on March 5, 2026 and are investigating. Unfortunately, there's no consumer-side workaround for this package-level issue at the moment.

In the meantime:

  • If you only need SAML/SSO functionality (not the dashboard), you may be able to use @better-auth/sso directly instead
  • Monitor issues #8332 and #8414 for updates on the fix
  • Ensure your project has "type": "module" in package.json (though this won't fully resolve the infra package issue)

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4063766985 --> @dosubot[bot] commented on GitHub (Mar 15, 2026): <!-- Greeting --> Hi @SleeveShirtholes! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue with the `@better-auth/infra` package. The package has a [critical CommonJS compatibility bug](https://github.com/better-auth/better-auth/issues/8332#issuecomment-3990282533) due to its `package.json` exports using the "import" condition instead of "default", which breaks serverless deployments like Netlify. The maintainers [acknowledged this issue on March 5, 2026](https://github.com/better-auth/better-auth/issues/8414#issuecomment-4004735517) and are investigating. Unfortunately, **there's no consumer-side workaround** for this package-level issue at the moment. **In the meantime:** - If you only need SAML/SSO functionality (not the dashboard), you may be able to use `@better-auth/sso` directly instead - Monitor issues [#8332](https://github.com/better-auth/better-auth/issues/8332) and [#8414](https://github.com/better-auth/better-auth/issues/8414) for updates on the fix - Ensure your project has `"type": "module"` in `package.json` (though this won't fully resolve the infra package issue) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/e050c64c-9f7e-4005-af28-4828c99b7077?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue%20with%20the%20%60%40better-auth/infra%60%20package.%20The%20package%20has%20a%20%5Bcritical%20CommonJS%20compatibility%20bug%5D%28https%3A//github.com/better-auth/better-auth/issues/8332%23issuecomment-3990282533%29%20due%20to%20its%20%60package.json%60%20exports%20using%20the%20%22import%22%20condition%20instead%20of%20%22default%22%2C%20which%20breaks%20serverless%20deployments%20like%20Netlify.%0A%0AThe%20maintainers%20%5Backnowledged%20this%20issue%20on%20March%205%2C%202026%5D%28https%3A//github.com/better-auth/better-auth/issues/8414%23issuecomment-4004735517%29%20and%20are%20investigating.%20Unfortunately%2C%20%2A%2Athere%27s%20no%20consumer-side%20workaround%2A%2A%20for%20this%20package-level%20issue%20at%20the%20moment.%0A%0A%2A%2AIn%20the%20meantime%3A%2A%2A%0A-%20If%20you%20only%20need%20SAML/SSO%20functionality%20%28not%20the%20dashboard%29%2C%20you%20may%20be%20able%20to%20use%20%60%40better-auth/sso%60%20directly%20instead%0A-%20Monitor%20issues%20%5B%238332%5D%28https%3A//github.com/better-auth/better-auth/issues/8332%29%20and%20%5B%238414%5D%28https%3A//github.com/better-auth/better-auth/issues/8414%29%20for%20updates%20on%20the%20fix%0A-%20Ensure%20your%20project%20has%20%60%22type%22%3A%20%22module%22%60%20in%20%60package.json%60%20%28though%20this%20won%27t%20fully%20resolve%20the%20infra%20package%20issue%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8620)
Author
Owner

@nkrkv commented on GitHub (Mar 27, 2026):

Here's a temp workaround until upstream fixes the bug. In your package.json add:

+  "resolutions": {
+    "samlify/camelcase": "6.3.0"
+  },

This instructs npm/yarn to use an older version of camelcase, which was still published with CJS support. This allows samlify to consume it with require.

<!-- gh-comment-id:4144647014 --> @nkrkv commented on GitHub (Mar 27, 2026): Here's a temp workaround until upstream fixes the bug. In your `package.json` add: ``` + "resolutions": { + "samlify/camelcase": "6.3.0" + }, ``` This instructs npm/yarn to use an older version of `camelcase`, which was still published with CJS support. This allows `samlify` to consume it with `require`.
Author
Owner

@jonathansamines commented on GitHub (Apr 1, 2026):

Hey @SleeveShirtholes @nkrkv , not too familiar with Netlify, but any chance are you trying to deploy to a target that does not support require(esm)?

Please note that we currently require your target environment to support that, for Node.js specifically that means:

Node 20 20.19.0
Node 22 22.12.0
<!-- gh-comment-id:4173245913 --> @jonathansamines commented on GitHub (Apr 1, 2026): Hey @SleeveShirtholes @nkrkv , not too familiar with Netlify, but any chance are you trying to deploy to a target that does not support [`require(esm)`](https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/)? Please note that we currently require your target environment to support that, for Node.js specifically that means: Node 20 | 20.19.0 -- | -- Node 22 | 22.12.0
Author
Owner

@nkrkv commented on GitHub (Apr 3, 2026):

I deploy to Vercel with Node 24. They probably don't support requiring ESM, but users don't have control over it anyway.

<!-- gh-comment-id:4185460358 --> @nkrkv commented on GitHub (Apr 3, 2026): I deploy to Vercel with Node 24. They probably don't support requiring ESM, but users don't have control over it anyway.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11140