[GH-ISSUE #886] Error: Cannot find module '@babel/core' #8483

Closed
opened 2026-04-13 03:33:45 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @drxc00 on GitHub (Dec 14, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/886

To Reproduce

  1. Create NextJs 15 app
  2. Config prisma orm
  3. Configure better-auth files (auth.ts, auth-client.ts, api routes)
  4. Run npx @better-auth/cli generate

Current vs. Expected behavior

Expected output should be related to the creation/addition of schema to the prisma.schema file. However, Im getting this error

node:internal/modules/cjs/loader:1249
  const err = new Error(message);
              ^

Error: Cannot find module '@babel/core'
Require stack:
- C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\helper-create-class-features-plugin\lib\index.js
- C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\plugin-transform-typescript\lib\index.js
- C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\preset-typescript\lib\index.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
    at Function._load (node:internal/modules/cjs/loader:1075:27)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:138:16)
    at Object.<anonymous> (C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\helper-create-class-features-plugin\lib\index.js:31:13)    
    at Module._compile (node:internal/modules/cjs/loader:1565:14)
    at Object..js (node:internal/modules/cjs/loader:1708:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\<name>\\AppData\\Local\\npm-cache\\_npx\\167ca1f116d365e6\\node_modules\\@babel\\helper-create-class-features-plugin\\lib\\index.js',
    'C:\\Users\\<name>\\AppData\\Local\\npm-cache\\_npx\\167ca1f116d365e6\\node_modules\\@babel\\plugin-transform-typescript\\lib\\index.js',
    'C:\\Users\\<name>\\AppData\\Local\\npm-cache\\_npx\\167ca1f116d365e6\\node_modules\\@babel\\preset-typescript\\lib\\index.js'
  ]
}

What version of Better Auth are you using?

1.0.20

Provide environment information

- OS: Windows 11

"devDependencies": {
    "@babel/cli": "^7.26.4",
    "@babel/core": "^7.26.0",
    "@babel/node": "^7.26.0",
    "@babel/preset-env": "^7.26.0",
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "babel-loader": "^9.2.1",
    "eslint": "^8",
    "eslint-config-next": "15.0.3",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }

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

Package

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import prisma from "./prisma-db";

export const auth = betterAuth({
    database: prismaAdapter(prisma, {
        provider: "postgresql",
    }),
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID as string,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
        }
    }
});

Additional context

No response

Originally created by @drxc00 on GitHub (Dec 14, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/886 ### To Reproduce 1. Create NextJs 15 app 2. Config prisma orm 3. Configure better-auth files (auth.ts, auth-client.ts, api routes) 4. Run npx @better-auth/cli generate ### Current vs. Expected behavior Expected output should be related to the creation/addition of schema to the `prisma.schema` file. However, Im getting this error ``` node:internal/modules/cjs/loader:1249 const err = new Error(message); ^ Error: Cannot find module '@babel/core' Require stack: - C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\helper-create-class-features-plugin\lib\index.js - C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\plugin-transform-typescript\lib\index.js - C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\preset-typescript\lib\index.js at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15) at Function._load (node:internal/modules/cjs/loader:1075:27) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:219:24) at Module.require (node:internal/modules/cjs/loader:1340:12) at require (node:internal/modules/helpers:138:16) at Object.<anonymous> (C:\Users\<name>\AppData\Local\npm-cache\_npx\167ca1f116d365e6\node_modules\@babel\helper-create-class-features-plugin\lib\index.js:31:13) at Module._compile (node:internal/modules/cjs/loader:1565:14) at Object..js (node:internal/modules/cjs/loader:1708:10) at Module.load (node:internal/modules/cjs/loader:1318:32) { code: 'MODULE_NOT_FOUND', requireStack: [ 'C:\\Users\\<name>\\AppData\\Local\\npm-cache\\_npx\\167ca1f116d365e6\\node_modules\\@babel\\helper-create-class-features-plugin\\lib\\index.js', 'C:\\Users\\<name>\\AppData\\Local\\npm-cache\\_npx\\167ca1f116d365e6\\node_modules\\@babel\\plugin-transform-typescript\\lib\\index.js', 'C:\\Users\\<name>\\AppData\\Local\\npm-cache\\_npx\\167ca1f116d365e6\\node_modules\\@babel\\preset-typescript\\lib\\index.js' ] } ``` ### What version of Better Auth are you using? 1.0.20 ### Provide environment information ```bash - OS: Windows 11 "devDependencies": { "@babel/cli": "^7.26.4", "@babel/core": "^7.26.0", "@babel/node": "^7.26.0", "@babel/preset-env": "^7.26.0", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "babel-loader": "^9.2.1", "eslint": "^8", "eslint-config-next": "15.0.3", "postcss": "^8", "tailwindcss": "^3.4.1", "typescript": "^5" } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import prisma from "./prisma-db"; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, } } }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:33:45 -05:00
Author
Owner

@raymondpattend commented on GitHub (Jan 29, 2025):

bump

<!-- gh-comment-id:2621866693 --> @raymondpattend commented on GitHub (Jan 29, 2025): bump
Author
Owner

@lst97 commented on GitHub (Feb 10, 2025):

@Rayrnond @drxc00 I think the issue may occure when we try to install better-auth in our existing project with complex peer dependency. I have the same issue while try to install better-auth into my Payload CMS after I have trying to fix it about an hour or two, and I accidentally fixed it.

package.json

{
...
  "dependencies": {
    "@payloadcms/db-postgres": "latest",
    "@payloadcms/email-nodemailer": "^3.22.0",
    "@payloadcms/next": "latest",
    "@payloadcms/payload-cloud": "latest",
    "@payloadcms/richtext-lexical": "latest",
    "@radix-ui/react-accordion": "^1.2.3",
    "@radix-ui/react-navigation-menu": "^1.2.5",
    "@radix-ui/themes": "^3.2.0",
    "@tailwindcss/postcss": "^4.0.5",
    "@types/pg": "^8.11.11",
    "@types/uuid": "^10.0.0",
    "better-auth": "^1.1.16",
    "cross-env": "^7.0.3",
    "date-fns": "^4.1.0",
    "framer-motion": "^12.4.1",
    "graphql": "^16.10.0",
    "lucide-react": "^0.474.0",
    "motion": "^12.4.1",
    "next": "15.1.6",
    "nodemailer": "^6.10.0",
    "payload": "latest",
    "pg": "^8.13.1",
    "react": "19.0.0",
    "react-dom": "19.0.0",
    "react-icons": "^5.4.0",
    "react-markdown": "^9.0.3",
    "react-toastify": "^11.0.3",
    "react-zoom-pan-pinch": "^3.7.0",
    "remark-breaks": "^4.0.0",
    "sharp": "0.33.5",
    "uuid": "^11.0.5",
    "zustand": "^5.0.3"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3.2.0",
    "@types/eslint__eslintrc": "^2.1.2",
    "@types/node": "^22.13.1",
    "@types/nodemailer": "^6.4.17",
    "@types/react": "19.0.8",
    "@types/react-dom": "19.0.3",
    "eslint": "^9.20.0",
    "eslint-config-next": "15.1.6",
    "postcss": "^8.5.1",
    "prettier": "^3.5.0",
    "tailwindcss": "^4.0.5",
    "typescript": "5.7.3"
  },
  "pnpm": {
    "onlyBuiltDependencies": [
      "sharp"
    ]
  }
}

I'm encountering an issue with @better-auth/cli on macOS 15.3. After installing @babel/core and running npx @better-auth/cli generate, I get a "@babel/core module not found" error. I've tried several troubleshooting steps without success, including:

  1. pnpm install @babel/core -> run npx @better-auth/cli generate -> @babel/core module not found
  2. changed different node version: 23.5, 22.13.1 (not working)
  3. npm cache clean --force (not working)
  4. use pnpm (not working)
  5. use yarn (not working)
  6. delete node_module then pnpm install (not working)
  7. delete all content in /Users/lst97/.npm -> run npx @better-auth/cli generate -> @babel/core module not found

Then I want to see what if I create a separate server as a new project, if it works?
After installing the better-auth and pg via pnpm, still not working.

Using conda virtual environment (default)
Now using node v23.5.0 (npm v11.1.0)
╭─ zsh   better-auth   0ms⠀                                     default 3.13.1  minikube :: default   65   10,16:11 
╰─ pnpm init                                
Wrote to /Users/lst97/Desktop/Yoons Cabinetry/yoons-cabinetry-backend/better-auth/package.json

{
  "name": "better-auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
╭─ zsh   better-auth   359ms⠀                       23.5.0  default 3.13.1  minikube :: default   65   10,16:11 
╰─ pnpm add better-auth
Packages: +26
++++++++++++++++++++++++++
Progress: resolved 26, reused 26, downloaded 0, added 26, done

dependencies:
+ better-auth 1.1.16

Done in 1.8s
╭─ zsh   better-auth   2s 123ms⠀                   󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:11 
╰─ git init
Initialized empty Git repository in /Users/lst97/Desktop/Yoons Cabinetry/yoons-cabinetry-backend/better-auth/.git/
╭─ zsh   better-auth   main ≢  ?4   62ms⠀                                                                                                                                                                                          󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:12 
╰─ pnpm add pg
Packages: +14
++++++++++++++
Progress: resolved 40, reused 39, downloaded 1, added 14, done

dependencies:
+ pg 8.13.1

Done in 697ms
╭─ zsh   better-auth   main ≢  ?4   967ms⠀                                                                                                                                                                                         󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:13 
╰─ pnpm i --save-dev @types/pg
Packages: +11
+++++++++++
Progress: resolved 51, reused 50, downloaded 1, added 11, done

devDependencies:
+ @types/pg 8.11.11

Done in 710ms
╭─ zsh   better-auth   main ≢  ?4   1s 1ms⠀                                                                                                                                                                                        󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:13 
╰─ npx @better-auth/cli generate
node:internal/modules/cjs/loader:1410
  const err = new Error(message);
              ^

Error: Cannot find module '@babel/core'
Require stack:
- /Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/helper-create-class-features-plugin/lib/index.js
- /Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/plugin-transform-typescript/lib/index.js
- /Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/preset-typescript/lib/index.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1410:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1061:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1066:22)
    at Function._load (node:internal/modules/cjs/loader:1215:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
    at Module.require (node:internal/modules/cjs/loader:1496:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/helper-create-class-features-plugin/lib/index.js:31:13)
    at Module._compile (node:internal/modules/cjs/loader:1740:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/helper-create-class-features-plugin/lib/index.js',
    '/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/plugin-transform-typescript/lib/index.js',
    '/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/preset-typescript/lib/index.js'
  ]
}

Node.js v23.5.0

Here is the ah ha moment, I do the step 6. delete all content in /Users/lst97/.npm -> run npx @better-auth/cli generate in the new project it suddenly works. The I go to my Payload CMS project run npx @better-auth/cli generate again, it magically work, not sure what happened.

Image

Here is the partial log that for my progress to try to run the npx @better-auth/cli generate from module not found to made it work.
cli-log.txt

Hope this help to fix your issue.

<!-- gh-comment-id:2646984039 --> @lst97 commented on GitHub (Feb 10, 2025): @Rayrnond @drxc00 I think the issue may occure when we try to install better-auth in our existing project with complex peer dependency. I have the same issue while try to install better-auth into my Payload CMS after I have trying to fix it about an hour or two, and I accidentally fixed it. `package.json` ```json { ... "dependencies": { "@payloadcms/db-postgres": "latest", "@payloadcms/email-nodemailer": "^3.22.0", "@payloadcms/next": "latest", "@payloadcms/payload-cloud": "latest", "@payloadcms/richtext-lexical": "latest", "@radix-ui/react-accordion": "^1.2.3", "@radix-ui/react-navigation-menu": "^1.2.5", "@radix-ui/themes": "^3.2.0", "@tailwindcss/postcss": "^4.0.5", "@types/pg": "^8.11.11", "@types/uuid": "^10.0.0", "better-auth": "^1.1.16", "cross-env": "^7.0.3", "date-fns": "^4.1.0", "framer-motion": "^12.4.1", "graphql": "^16.10.0", "lucide-react": "^0.474.0", "motion": "^12.4.1", "next": "15.1.6", "nodemailer": "^6.10.0", "payload": "latest", "pg": "^8.13.1", "react": "19.0.0", "react-dom": "19.0.0", "react-icons": "^5.4.0", "react-markdown": "^9.0.3", "react-toastify": "^11.0.3", "react-zoom-pan-pinch": "^3.7.0", "remark-breaks": "^4.0.0", "sharp": "0.33.5", "uuid": "^11.0.5", "zustand": "^5.0.3" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", "@types/eslint__eslintrc": "^2.1.2", "@types/node": "^22.13.1", "@types/nodemailer": "^6.4.17", "@types/react": "19.0.8", "@types/react-dom": "19.0.3", "eslint": "^9.20.0", "eslint-config-next": "15.1.6", "postcss": "^8.5.1", "prettier": "^3.5.0", "tailwindcss": "^4.0.5", "typescript": "5.7.3" }, "pnpm": { "onlyBuiltDependencies": [ "sharp" ] } } ``` ## I'm encountering an issue with @better-auth/cli on macOS 15.3. After installing @babel/core and running npx @better-auth/cli generate, I get a "@babel/core module not found" error. I've tried several troubleshooting steps without success, including: 0. pnpm install @babel/core -> run `npx @better-auth/cli generate` -> @babel/core module not found 1. changed different node version: 23.5, 22.13.1 (not working) 2. npm cache clean --force (not working) 3. use pnpm (not working) 4. use yarn (not working) 5. delete node_module then pnpm install (not working) 6. delete all content in /Users/lst97/.npm -> run `npx @better-auth/cli generate` -> @babel/core module not found Then I want to see what if I create a separate server as a new project, if it works? After installing the better-auth and pg via pnpm, still not working. ```sh Using conda virtual environment (default) Now using node v23.5.0 (npm v11.1.0) ╭─ zsh   better-auth   0ms⠀  default 3.13.1  minikube :: default   65   10,16:11  ╰─ pnpm init Wrote to /Users/lst97/Desktop/Yoons Cabinetry/yoons-cabinetry-backend/better-auth/package.json { "name": "better-auth", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } ╭─ zsh   better-auth   359ms⠀   23.5.0  default 3.13.1  minikube :: default   65   10,16:11  ╰─ pnpm add better-auth Packages: +26 ++++++++++++++++++++++++++ Progress: resolved 26, reused 26, downloaded 0, added 26, done dependencies: + better-auth 1.1.16 Done in 1.8s ╭─ zsh   better-auth   2s 123ms⠀  󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:11  ╰─ git init Initialized empty Git repository in /Users/lst97/Desktop/Yoons Cabinetry/yoons-cabinetry-backend/better-auth/.git/ ╭─ zsh   better-auth   main ≢  ?4   62ms⠀  󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:12  ╰─ pnpm add pg Packages: +14 ++++++++++++++ Progress: resolved 40, reused 39, downloaded 1, added 14, done dependencies: + pg 8.13.1 Done in 697ms ╭─ zsh   better-auth   main ≢  ?4   967ms⠀  󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:13  ╰─ pnpm i --save-dev @types/pg Packages: +11 +++++++++++ Progress: resolved 51, reused 50, downloaded 1, added 11, done devDependencies: + @types/pg 8.11.11 Done in 710ms ╭─ zsh   better-auth   main ≢  ?4   1s 1ms⠀  󰋁 23.5.0  default 3.13.1  minikube :: default   65   10,16:13  ╰─ npx @better-auth/cli generate node:internal/modules/cjs/loader:1410 const err = new Error(message); ^ Error: Cannot find module '@babel/core' Require stack: - /Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/helper-create-class-features-plugin/lib/index.js - /Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/plugin-transform-typescript/lib/index.js - /Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/preset-typescript/lib/index.js at Function._resolveFilename (node:internal/modules/cjs/loader:1410:15) at defaultResolveImpl (node:internal/modules/cjs/loader:1061:19) at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1066:22) at Function._load (node:internal/modules/cjs/loader:1215:37) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:234:24) at Module.require (node:internal/modules/cjs/loader:1496:12) at require (node:internal/modules/helpers:135:16) at Object.<anonymous> (/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/helper-create-class-features-plugin/lib/index.js:31:13) at Module._compile (node:internal/modules/cjs/loader:1740:14) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/helper-create-class-features-plugin/lib/index.js', '/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/plugin-transform-typescript/lib/index.js', '/Users/lst97/.npm/_npx/167ca1f116d365e6/node_modules/@babel/preset-typescript/lib/index.js' ] } Node.js v23.5.0 ``` ### Here is the ah ha moment, I do the step 6. delete all content in /Users/lst97/.npm -> run `npx @better-auth/cli generate` in the new project it suddenly works. The I go to my Payload CMS project run `npx @better-auth/cli generate` again, it magically work, not sure what happened. ![Image](https://github.com/user-attachments/assets/17e94888-0cda-4484-bfa5-7e8b6de9a396) Here is the partial log that for my progress to try to run the `npx @better-auth/cli generate` from module not found to made it work. [cli-log.txt](https://github.com/user-attachments/files/18728677/cli-log.txt) Hope this help to fix your issue.
Author
Owner

@danhstevens commented on GitHub (Feb 20, 2025):

I was able to get it to run using bunx instead of npx: bunx --bun @better-auth/cli generate

Hope they get the underlying cause fixed soon!

<!-- gh-comment-id:2672833936 --> @danhstevens commented on GitHub (Feb 20, 2025): I was able to get it to run using `bunx` instead of `npx`: `bunx --bun @better-auth/cli generate` Hope they get the underlying cause fixed soon!
Author
Owner

@krisnaw commented on GitHub (Mar 5, 2025):

This is the solution: https://github.com/better-auth/better-auth/issues/1467#issuecomment-2697346123

<!-- gh-comment-id:2700685299 --> @krisnaw commented on GitHub (Mar 5, 2025): This is the solution: https://github.com/better-auth/better-auth/issues/1467#issuecomment-2697346123
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8483