Cannot find module 'universalify' #1827

Closed
opened 2026-03-13 09:06:04 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @thatanjan on GitHub (Sep 2, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a Nextjs app
  2. Install better-auth and the auth.js config
  3. Try to generate schema with CLI using following command:
npx @better-auth/cli generate

Current vs. Expected behavior

Expected: No error should Appear

Current: I get error Cannot find module 'universalify'. Full log:

❯ npx @better-auth/cli generate
node:internal/modules/cjs/loader:1383
  const err = new Error(message);
              ^

Error: Cannot find module 'universalify'
Require stack:
- /home/anjan/.npm/_npx/167ca1f116d365e6/node_modules/fs-extra/lib/fs/index.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1383:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)
    at Function._load (node:internal/modules/cjs/loader:1192:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)
    at Module.require (node:internal/modules/cjs/loader:1463:12)
    at require (node:internal/modules/helpers:147:16)
    at Object.<anonymous> (/home/anjan/.npm/_npx/167ca1f116d365e6/node_modules/fs-extra/lib/fs/index.js:4:11)
    at Module._compile (node:internal/modules/cjs/loader:1706:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/anjan/.npm/_npx/167ca1f116d365e6/node_modules/fs-extra/lib/fs/index.js'
  ]
}

What version of Better Auth are you using?

^1.3.7

System info

System:
    OS: Linux 6.16 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor
    Memory: 22.78 GB / 31.27 GB
    Container: Yes
    Shell: 4.0.2 - /usr/bin/fish
  Browsers:
    Brave Browser: 139.1.81.137

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

Package

Auth config (if applicable)

// src/lib/auth.js
import { betterAuth } from 'better-auth'
import Database from 'better-sqlite3'

export const auth = betterAuth({
  database: new Database('./sqlite.db'),
})

Additional context

I tried these node versions, but there was no change.

  • v22.19.0
  • v23.11.1
  • v24.7.0

I installed universalify package both globally and as a dev dependency. But still not working.

I have read common issues section in the doc. But there isn't an alias used in the config. This is the first time I'm trying to use better-auth. Please let me know if I am missing anything.

Originally created by @thatanjan on GitHub (Sep 2, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a Nextjs app 2. Install better-auth and the `auth.js` config 3. Try to generate schema with CLI using following command: ```bash npx @better-auth/cli generate ``` ### Current vs. Expected behavior Expected: No error should Appear Current: I get error `Cannot find module 'universalify'`. Full log: ``` ❯ npx @better-auth/cli generate node:internal/modules/cjs/loader:1383 const err = new Error(message); ^ Error: Cannot find module 'universalify' Require stack: - /home/anjan/.npm/_npx/167ca1f116d365e6/node_modules/fs-extra/lib/fs/index.js at Function._resolveFilename (node:internal/modules/cjs/loader:1383:15) at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19) at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22) at Function._load (node:internal/modules/cjs/loader:1192:37) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:237:24) at Module.require (node:internal/modules/cjs/loader:1463:12) at require (node:internal/modules/helpers:147:16) at Object.<anonymous> (/home/anjan/.npm/_npx/167ca1f116d365e6/node_modules/fs-extra/lib/fs/index.js:4:11) at Module._compile (node:internal/modules/cjs/loader:1706:14) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/anjan/.npm/_npx/167ca1f116d365e6/node_modules/fs-extra/lib/fs/index.js' ] } ``` ### What version of Better Auth are you using? ^1.3.7 ### System info ```bash System: OS: Linux 6.16 Arch Linux CPU: (12) x64 AMD Ryzen 5 5600 6-Core Processor Memory: 22.78 GB / 31.27 GB Container: Yes Shell: 4.0.2 - /usr/bin/fish Browsers: Brave Browser: 139.1.81.137 ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript // src/lib/auth.js import { betterAuth } from 'better-auth' import Database from 'better-sqlite3' export const auth = betterAuth({ database: new Database('./sqlite.db'), }) ``` ### Additional context I tried these node versions, but there was no change. * v22.19.0 * v23.11.1 * v24.7.0 I installed `universalify` package both globally and as a dev dependency. But still not working. I have read [common issues](https://www.better-auth.com/docs/concepts/cli#common-issues) section in the doc. But there isn't an alias used in the config. This is the first time I'm trying to use better-auth. Please let me know if I am missing anything.
GiteaMirror added the bug label 2026-03-13 09:06:04 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 2, 2025):

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

This error is caused by a dependency resolution issue with the Better Auth CLI when run via npx. The CLI depends on fs-extra, which in turn depends on universalify as a transitive dependency. If universalify is missing, it usually means npx did not install all transitive dependencies correctly, or there is a packaging issue with the CLI on npm. Installing universalify globally or as a dev dependency in your project will not fix this, since the CLI expects it in its own node_modules.

The most reliable workaround is to install @better-auth/cli as a dev dependency in your project (instead of using npx), which ensures all dependencies are resolved properly. Run:

npm install --save-dev @better-auth/cli
# or
yarn add --dev @better-auth/cli
# or
pnpm add -D @better-auth/cli

Then use the CLI via your package manager:

npx better-auth-cli generate
# or
pnpm better-auth-cli generate
# or
yarn better-auth-cli generate

This approach has resolved similar "Cannot find module" errors for other users and is recommended for CLI versions 1.3.5 and above (source).

If you still see the error, try clearing your npx cache (npx clear-npx-cache) or, as a last resort, temporarily downgrade to CLI version 1.3.4, which does not have this issue (source).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 2, 2025): <!-- Greeting --> Hi @thatanjan! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This error is caused by a dependency resolution issue with the Better Auth CLI when run via npx. The CLI depends on `fs-extra`, which in turn depends on `universalify` as a transitive dependency. If `universalify` is missing, it usually means npx did not install all transitive dependencies correctly, or there is a packaging issue with the CLI on npm. Installing `universalify` globally or as a dev dependency in your project will not fix this, since the CLI expects it in its own node_modules. The most reliable workaround is to install `@better-auth/cli` as a dev dependency in your project (instead of using npx), which ensures all dependencies are resolved properly. Run: ```bash npm install --save-dev @better-auth/cli # or yarn add --dev @better-auth/cli # or pnpm add -D @better-auth/cli ``` Then use the CLI via your package manager: ```bash npx better-auth-cli generate # or pnpm better-auth-cli generate # or yarn better-auth-cli generate ``` This approach has resolved similar "Cannot find module" errors for other users and is recommended for CLI versions 1.3.5 and above ([source](https://github.com/better-auth/better-auth/issues/3951)). If you still see the error, try clearing your npx cache (`npx clear-npx-cache`) or, as a last resort, temporarily downgrade to CLI version 1.3.4, which does not have this issue ([source](https://github.com/better-auth/better-auth/issues/3951)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e7ede8b5-4377-4002-b9f1-efa9c0335760?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&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/4359)
Author
Owner

@himself65 commented on GitHub (Sep 2, 2025):

can you try 1.3.8-beta.10?

npx @better-auth/cli@1.3.8-beta.10 generate

@himself65 commented on GitHub (Sep 2, 2025): can you try [1.3.8-beta.10](https://www.npmjs.com/package/better-auth/v/1.3.8-beta.10)? `npx @better-auth/cli@1.3.8-beta.10 generate`
Author
Owner

@thatanjan commented on GitHub (Sep 2, 2025):

@himself65 I tried the beta version. It worked, thanks 🙏🏻.
Though I got an error at first:

2025-09-02T07:57:10.351Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'better-sqlite3

But after installing better-sqlite3, everything worked fine

@thatanjan commented on GitHub (Sep 2, 2025): @himself65 I tried the beta version. It worked, thanks 🙏🏻. Though I got an error at first: ``` 2025-09-02T07:57:10.351Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'better-sqlite3 ``` But after installing better-sqlite3, everything worked fine
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1827