#11459·better-auth

@better-auth/telemetry makes Vercel's file tracer bundle every package.json in node_modules into each serverless function

Author: paisanolucianoCreated Sep 28, 2026Updated Sep 28, 2026

Is this suited for github?

  • Yes, this is suited for github

Reproduction

@better-auth/telemetry/dist/node.mjs (1.7.6) reads package versions like this:

javascript
const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");
const raw = await fsPromises.readFile(pkgJsonPath, "utf-8");

pkg comes from a loop, so @vercel/nft can't resolve it statically. It expands the path to node_modules/*/package.json and copies every package.json in node_modules into every function that imports better-auth. Vercel, Next.js output tracing and other serverless bundlers use nft.

This happens with telemetry disabled, because tracing is static. better-auth, better-auth/minimal and context/create-context.mjs all import @better-auth/telemetry, so no entry point avoids it.

Minimal reproduction

javascript
// entry.mjs
import { betterAuth } from "better-auth";
export const auth = betterAuth({});
javascript
// trace.mjs
import { nodeFileTrace } from "@vercel/nft";
const { fileList, reasons } = await nodeFileTrace(["entry.mjs"], { base: process.cwd() });
const viaTelemetry = [...fileList].filter((f) => {
  const parents = [...(reasons.get(f)?.parents ?? [])];
  return parents.length > 0 && parents.every((p) => p.includes("@better-auth/telemetry"));
});
console.log("traced files:", fileList.size);
console.log("added only by @better-auth/telemetry:", viaTelemetry.length);
console.log("unused is-number/package.json traced:", fileList.has("node_modules/is-number/package.json"));
console.log("is-number/index.js traced:", fileList.has("node_modules/is-number/index.js"));

Output:

traced files: 816
added only by @better-auth/telemetry: 81
unused is-number/package.json traced: true
is-number/index.js traced: false

Nothing imports is-number, but its package.json ships with the function.

Impact in a real app

  • Our app has about 2,360 package.json files in node_modules and 257 Vercel functions. 212 of them load Better Auth.
  • Traced files across all functions went from 613,410 to 1,094,104.
  • vercel build went from about 15 to 48 minutes in the release that upgraded better-auth from 1.3.7 to 1.7.6. Other changes shipped in the same release.
  • Functions now hold package.json files for packages whose code isn't included. Our deploy check looked for sharp/package.json to find a function that uses sharp, loaded one that had no sharp/lib, and failed.

Suggested fix

Read versions only from the root package.json, which getVersionFromLocalPackageJson already does as a fallback. Or check a fixed list of package names with literal paths the tracer can resolve. We use this patch as a workaround, and it removes the extra files in our trace:

diff
 async function getPackageVersion(pkg) {
-	if (packageJSONCache) return packageJSONCache.dependencies?.[pkg] || packageJSONCache.devDependencies?.[pkg] || packageJSONCache.peerDependencies?.[pkg];
-	try {
-		const cwd = process.cwd();
-		if (!cwd) throw new Error("no-cwd");
-		const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");
-		const raw = await fsPromises.readFile(pkgJsonPath, "utf-8");
-		return JSON.parse(raw).version || await getVersionFromLocalPackageJson(pkg) || void 0;
-	} catch {}
 	return getVersionFromLocalPackageJson(pkg);
 }

Environment

better-auth 1.7.6, @better-auth/telemetry 1.7.6, @vercel/nft 1.1.1, Vercel CLI 48.12.1, Node 22, pnpm 9.12.2 with node-linker=hoisted.

Current vs. Expected behavior

Current: Any file that imports better-auth also pulls in @better-auth/telemetry/dist/node.mjs, which reads package versions with a runtime package name:

javascript
const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");

@vercel/nft can't resolve pkg statically, so it expands the path to node_modules/*/package.json. Every package.json in node_modules gets copied into every serverless function that loads Better Auth. This happens even with telemetry disabled, because tracing is static. better-auth, better-auth/minimal and context/create-context.mjs all import the telemetry module, so no entry point avoids it.

In a clean install ([email protected], @vercel/[email protected], plus an unused [email protected]), tracing a one-line import { betterAuth } from "better-auth" gives:

traced files: 816
added only by @better-auth/telemetry: 81
unused is-number/package.json traced: true
is-number/index.js traced: false

Expected: Importing Better Auth traces only the files Better Auth actually loads. Telemetry version detection shouldn't add package.json files for unrelated packages to the deployment bundle, especially when telemetry is off.

What version of Better Auth are you using?

better-auth 1.7.6, @better-auth/telemetry 1.7.6, @vercel/nft 1.1.1, Vercel CLI 48.12.1, Node 22, pnpm 9.12.2 with node-linker=hoisted.

System info

bash
- better-auth: 1.7.6
- @better-auth/telemetry: 1.7.6
- @vercel/nft: 1.1.1 (standalone reproduction)
- Vercel CLI: 48.12.1 (`vercel build --standalone`)
- Node: 22
- pnpm: 9.12.2 with `node-linker=hoisted`
- OS: Linux x64 (CI build runner); also reproduced on macOS arm64
- Runtime: Vercel Node.js serverless functions
- Telemetry: disabled (`BETTER_AUTH_TELEMETRY_ENDPOINT` not set)

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

Package

Auth config (if applicable)

typescript
import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

Impact in our app, which has about 2,360 package.json files in node_modules and 257 Vercel functions, 212 of which load Better Auth:

  • Traced files across all functions went from 613,410 to 1,094,104.
  • vercel build went from about 15 to 48 minutes in the release that upgraded better-auth from 1.3.7 to 1.7.6. Other changes shipped in the same release.
  • Functions now hold package.json files for packages whose code isn't included. Our deploy check looked for sharp/package.json to find a function that uses sharp, loaded one that had no sharp/lib, and failed.

Suggested fix: read versions only from the root package.json, which getVersionFromLocalPackageJson already does as a fallback. Or check a fixed list of package names with literal paths the tracer can resolve.

Our workaround is a pnpm patch that removes the extra files in our trace:

diff
 async function getPackageVersion(pkg) {
-	if (packageJSONCache) return packageJSONCache.dependencies?.[pkg] || packageJSONCache.devDependencies?.[pkg] || packageJSONCache.peerDependencies?.[pkg];
-	try {
-		const cwd = process.cwd();
-		if (!cwd) throw new Error("no-cwd");
-		const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");
-		const raw = await fsPromises.readFile(pkgJsonPath, "utf-8");
-		return JSON.parse(raw).version || await getVersionFromLocalPackageJson(pkg) || void 0;
-	} catch {}
 	return getVersionFromLocalPackageJson(pkg);
 }