-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js duild fails in Docker due to missing DATABASE_URL with Prisma and BetterAuth #77436
Comments
@mcorbelli env file name shouldn't have example. Please rename it to .env or refer to the following link https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables |
I don’t understand why an .env file would be needed during the build process. From my experience, environment variables like DATABASE_URL are typically set at runtime rather than at build time. Also, embedding the database URL directly into the image seems risky, as it could expose sensitive credentials if the image is shared or deployed incorrectly. Usually, I rename .env.example to .env.local for local development, while production environments manage secrets separately. Could you clarify why the build process requires an .env file? Wouldn’t it be safer to provide the database URL at runtime instead? |
Welcome to the funny dev world of 2025 where apparently people are creating dedicated builds for specific environments with baked-in environment-specific configuration. I've been building web apps for the last 25 years and configuration was ALWAYS done at run-time. But if you ask why things are the way they are in Next.js-land you get looked at like you're some kind of psycho from the middleages. 😄 Accessing your database from within your build pipeline is also perfectly normal nowadays. Of course, you're using some database SaaS provider and your database is accessible from anywhere (including your CI), right? Right? 😉 But I digress… In your case, I suppose this happens because the route in I worked around this by making let _auth: Auth | undefined;
export const auth() = () => {
_auth ??= ... do auth setup
return _auth;
} Now I need to use |
Link to the code that reproduces this issue
https://github.com/mcorbelli/hello-world
To Reproduce
Current vs. Expected behavior
Current behavior:
The build fails with the following error:
Expected behavior:
The build should proceed successfully without Prisma failing due to a missing DATABASE_URL, given that the affected files are marked as dynamic and that the variable is properly set in the environment.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 24.4.0: Wed Mar 12 21:24:23 PDT 2025; root:xnu-11417.101.13~4/RELEASE_ARM64_T6030 Available memory (MB): 18432 Available CPU cores: 12 Binaries: Node: 22.12.0 npm: 10.9.0 Yarn: N/A pnpm: 10.6.3 Relevant Packages: next: 15.2.3 // Latest available version is detected (15.2.3). eslint-config-next: N/A react: 19.0.0 react-dom: 19.0.0 typescript: N/A Next.js Config: output: standalone
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
I’m trying to deploy my Next.js project in a Docker container, but the build process fails due to a missing DATABASE_URL environment variable.
I use BetterAuth for authentication, and in my package configuration, I retrieve settings from the database using Prisma. The affected files are marked as dynamic (e.g., dynamic = "force-dynamic"), but the issue persists.
The text was updated successfully, but these errors were encountered: