something worong with cloudfalre

Hi everyone, I'm encountering an issue while deploying my Next.js project to Cloudflare Workers using OpenNext, and I'm also using better-auth for user authentication. I'm getting the following error: ```json { "source": { "level": "error", "message": "# SERVER_ERROR: Error: [unenv] fs.readdir is not implemented yet!", "$cloudflare": { "$metadata": { "id": "<CLOUDFLARE_REQUEST_ID>", "type": "cf-worker", "error": "# SERVER_ERROR: Error: [unenv] fs.readdir is not implemented yet!", "errorPattern": "# SERVER_ERROR: Error: [unenv] <DOMAIN> is not implemented yet!", "messagePattern": "# SERVER_ERROR: Error: [unenv] <DOMAIN> is not implemented yet!" } } }, "dataset": "cloudflare-workers", "timestamp": "2025-04-19T14:33:06.184Z", "$workers": { "truncated": false, "event": { "request": { "url": "https://<domain>/api/auth/sign-in/social", "method": "POST", "path": "/api/auth/sign-in/social" } }, "outcome": "ok", "scriptName": "cloudflare", "eventType": "fetch", "executionModel": "stateless", "scriptVersion": { "id": "<WORKER_VERSION_ID>" }, "requestId": "<REQUEST_ID>" }, "$metadata": { "id": "<CLOUDFLARE_REQUEST_ID>", "requestId": "<REQUEST_ID>", "trigger": "POST /api/auth/sign-in/social", "service": "cloudflare", "level": "error", "error": "# SERVER_ERROR: Error: [unenv] fs.readdir is not implemented yet!", "message": "# SERVER_ERROR: Error: [unenv] fs.readdir is not implemented yet!", "account": "<YOUR_CLOUDFLARE_ACCOUNT_ID>", "type": "cf-worker", "fingerprint": "<WORKER_FINGERPRINT>", "origin": "fetch", "messageTemplate": "# SERVER_ERROR: Error: [unenv] <DOMAIN> is not implemented yet!", "errorTemplate": "# SERVER_ERROR: Error: [unenv] <DOMAIN> is not implemented yet!" }, "links": [] }
2 Replies
Ping
Ping2w ago
I don't think that's an error coming from any better-auth internal code as we don't use fs.
PDDO
PDDOOP2w ago
this is my better-auth init
typescript import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import { passkey } from "better-auth/plugins/passkey";
import prisma, { cfEnv } from "./db";

export const auth = betterAuth({
database: prismaAdapter(prisma, { provider: "postgresql" }),
secondaryStorage: {
get: (key) => cfEnv.env.KV.get(key),
set: async (key, value, ttl) => {
return await cfEnv.env.KV.put(key, value, { expirationTtl: ttl });
},
delete: (key) => cfEnv.env.KV.delete(key),
},
socialProviders: {
github: {
clientId: cfEnv.env.GITHUB_CLIENT_ID,
clientSecret: cfEnv.env.GITHUB_CLIENT_SECRET,
},
google: {
clientId: cfEnv.env.GOOGLE_CLIENT_ID,
clientSecret: cfEnv.env.GOOGLE_CLIENT_SECRET,
},
},
plugins: [
nextCookies(),
passkey({
rpID: "localhost",
rpName: "localhost",
}),
],
user: {
additionalFields: {
role: {
type: "string",
input: false,
},
notify: {
type: "boolean",
input: false,
},
},
},
});
typescript import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import { passkey } from "better-auth/plugins/passkey";
import prisma, { cfEnv } from "./db";

export const auth = betterAuth({
database: prismaAdapter(prisma, { provider: "postgresql" }),
secondaryStorage: {
get: (key) => cfEnv.env.KV.get(key),
set: async (key, value, ttl) => {
return await cfEnv.env.KV.put(key, value, { expirationTtl: ttl });
},
delete: (key) => cfEnv.env.KV.delete(key),
},
socialProviders: {
github: {
clientId: cfEnv.env.GITHUB_CLIENT_ID,
clientSecret: cfEnv.env.GITHUB_CLIENT_SECRET,
},
google: {
clientId: cfEnv.env.GOOGLE_CLIENT_ID,
clientSecret: cfEnv.env.GOOGLE_CLIENT_SECRET,
},
},
plugins: [
nextCookies(),
passkey({
rpID: "localhost",
rpName: "localhost",
}),
],
user: {
additionalFields: {
role: {
type: "string",
input: false,
},
notify: {
type: "boolean",
input: false,
},
},
},
});
I did not manually trigger fs API. I think the path that triggered this error is caused by better-auth.

Did you find this page helpful?