ExpressJS app crashes when deploying to Railway

/app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs:315
undefined
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/.pnpm/@noble+ciphers@2.0.0/node_modules/@noble/ciphers/chacha.js from /app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs not supported.
Instead change the require of chacha.js in /app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object.<anonymous> (/app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs:4:19) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.11.0
/app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs:315
undefined
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/.pnpm/@noble+ciphers@2.0.0/node_modules/@noble/ciphers/chacha.js from /app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs not supported.
Instead change the require of chacha.js in /app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object.<anonymous> (/app/node_modules/.pnpm/better-auth@1.3.13/node_modules/better-auth/dist/crypto/index.cjs:4:19) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.11.0
Similiar issue: https://discord.com/channels/1288403910284935179/1415884972736118814
7 Replies
Sulek
SulekOP3d ago
package.json:
{
"name": "backend",
"version": "1.0.0",
"description": "Web API for Vending",
"main": "index.ts",
"scripts": {
"start": "node dist/index.js",
"build": "tsc",
"dev": "tsx watch src/index.ts",
"ba:generate": "npx @better-auth/cli@latest generate --output ./src/db/schema/auth.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"seed:prod": "tsx -r dotenv/config src/utils/seed.ts"
},
"author": "",
"license": "ISC",
"engines": {
"node": "22.x"
},
"dependencies": {
"bcrypt": "^6.0.0",
"better-auth": "^1.3.13",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"date-fns": "^4.1.0",
"dotenv": "^17.0.1",
"dotenv-expand": "^12.0.2",
"drizzle-orm": "^0.44.2",
"drizzle-zod": "^0.8.2",
"express": "^5.1.0",
"express-rate-limit": "^8.0.1",
"helmet": "^8.1.0",
"jsonwebtoken": "^9.0.2",
"ms": "^2.1.3",
"pg": "^8.16.3",
"pino": "^9.7.0",
"pino-http": "^10.5.0",
"pino-pretty": "^13.0.0",
"zod": "^3.25.75"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.9",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/express-rate-limit": "^5.1.3",
"@types/helmet": "^0.0.48",
"@types/jsonwebtoken": "^9.0.10",
"@types/ms": "^2.1.0",
"@types/node": "^24.0.10",
"@types/pg": "^8.15.4",
"@types/pino": "^7.0.4",
"drizzle-kit": "^0.31.4",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
}
}
{
"name": "backend",
"version": "1.0.0",
"description": "Web API for Vending",
"main": "index.ts",
"scripts": {
"start": "node dist/index.js",
"build": "tsc",
"dev": "tsx watch src/index.ts",
"ba:generate": "npx @better-auth/cli@latest generate --output ./src/db/schema/auth.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"seed:prod": "tsx -r dotenv/config src/utils/seed.ts"
},
"author": "",
"license": "ISC",
"engines": {
"node": "22.x"
},
"dependencies": {
"bcrypt": "^6.0.0",
"better-auth": "^1.3.13",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"date-fns": "^4.1.0",
"dotenv": "^17.0.1",
"dotenv-expand": "^12.0.2",
"drizzle-orm": "^0.44.2",
"drizzle-zod": "^0.8.2",
"express": "^5.1.0",
"express-rate-limit": "^8.0.1",
"helmet": "^8.1.0",
"jsonwebtoken": "^9.0.2",
"ms": "^2.1.3",
"pg": "^8.16.3",
"pino": "^9.7.0",
"pino-http": "^10.5.0",
"pino-pretty": "^13.0.0",
"zod": "^3.25.75"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.9",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/express-rate-limit": "^5.1.3",
"@types/helmet": "^0.0.48",
"@types/jsonwebtoken": "^9.0.10",
"@types/ms": "^2.1.0",
"@types/node": "^24.0.10",
"@types/pg": "^8.15.4",
"@types/pino": "^7.0.4",
"drizzle-kit": "^0.31.4",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
}
}
braga
braga2d ago
I'm trying to deploy my backend on Vercel, and I'm getting error logs similar to these, but in a different package.
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/index.js from /var/task/node_modules/.pnpm/@better-auth+core@1.3.28_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-cal_5523256296096d34052ebac5b152f80c/node_modules/@better-auth/core/dist/social-providers/index.cjs not supported.
Instead change the require of index.js in /var/task/node_modules/.pnpm/@better-auth+core@1.3.28_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-cal_5523256296096d34052ebac5b152f80c/node_modules/@better-auth/core/dist/social-providers/index.cjs to a dynamic import() which is available in all CommonJS modules.
at /opt/rust/nodejs.js:2:13528
at Function.Vr (/opt/rust/nodejs.js:2:13906)
at Ue.e.<computed>.Be._load (/opt/rust/nodejs.js:2:13498)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/.pnpm/jose@6.1.0/node_modules/jose/dist/webapi/index.js from /var/task/node_modules/.pnpm/@better-auth+core@1.3.28_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-cal_5523256296096d34052ebac5b152f80c/node_modules/@better-auth/core/dist/social-providers/index.cjs not supported.
Instead change the require of index.js in /var/task/node_modules/.pnpm/@better-auth+core@1.3.28_@better-auth+utils@0.3.0_@better-fetch+fetch@1.1.18_better-cal_5523256296096d34052ebac5b152f80c/node_modules/@better-auth/core/dist/social-providers/index.cjs to a dynamic import() which is available in all CommonJS modules.
at /opt/rust/nodejs.js:2:13528
at Function.Vr (/opt/rust/nodejs.js:2:13906)
at Ue.e.<computed>.Be._load (/opt/rust/nodejs.js:2:13498)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
can you help us @Alex Yang
Alex Yang
Alex Yang2d ago
let me check What is your nodejs version?
braga
braga2d ago
22.x What I found strange in my tests is that when I deployed my backend on Render, I was successful, but deploying on Vercel, even with numerous changes, the error persists.
Alex Yang
Alex Yang2d ago
I think maybe they have different node.js version
braga
braga2d ago
on vercel using 22.x but on render i don't find the node version after some research I found the default version of node js used in render: 22.16.0
Alex Yang
Alex Yang2d ago
the reason is jose 6 doesn't support CJS. So I think you can add type:module in pacakge.json and try to migrate to ESM

Did you find this page helpful?