[GH-ISSUE #469] Error with nanoid module #8282

Closed
opened 2026-04-13 03:21:34 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @alfUMi on GitHub (Nov 8, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/469

Describe the bug
Error [ERR_REQUIRE_ESM]: require() of ES Module \node_modules\nanoid\index.js from \node_modules\better-auth\dist\index.cjs not supported.
Instead change the require of index.js in \node_modules\better-auth\dist\index.cjs to a dynamic import() which is available in all CommonJS modules.

To Reproduce
This is my betterAuth initialization code. Upon further use, the server crashes and returns an error

import { betterAuth } from 'better-auth'
import { prismaAdapter } from 'better-auth/adapters/prisma'

import { prisma } from '@/config/database'

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

Additional context
I use NodeJS with Express.

Here is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2021",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "rootDir": "src",
    "outDir": "dist",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "ts-node": {
    "require": ["tsconfig-paths/register"]
  }
}
Originally created by @alfUMi on GitHub (Nov 8, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/469 **Describe the bug** Error [ERR_REQUIRE_ESM]: require() of ES Module \node_modules\nanoid\index.js from \node_modules\better-auth\dist\index.cjs not supported. Instead change the require of index.js in \node_modules\better-auth\dist\index.cjs to a dynamic import() which is available in all CommonJS modules. **To Reproduce** This is my betterAuth initialization code. Upon further use, the server crashes and returns an error ```ts import { betterAuth } from 'better-auth' import { prismaAdapter } from 'better-auth/adapters/prisma' import { prisma } from '@/config/database' export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', }), }) ``` **Additional context** I use NodeJS with Express. Here is my tsconfig.json: ```json { "compilerOptions": { "target": "es2021", "module": "commonjs", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, "rootDir": "src", "outDir": "dist", "paths": { "@/*": ["./src/*"] } }, "ts-node": { "require": ["tsconfig-paths/register"] } } ```
GiteaMirror added the locked label 2026-04-13 03:21:34 -05:00
Author
Owner

@norjamille-kasan commented on GitHub (Dec 5, 2024):

i encountered the same issue. any work around to this?

<!-- gh-comment-id:2520213157 --> @norjamille-kasan commented on GitHub (Dec 5, 2024): i encountered the same issue. any work around to this?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8282