[EXPERIMENTAL/V5 (+Next 14)]: Build fails because of Database Adapter #8996
Unanswered
theopomies
asked this question in
Help
Replies: 1 comment 5 replies
-
Hmm.You did add a env variable check though, so this is expected and unrelated to NextAuth.js. You could move the typencheck to something like https://env.t3.gg/docs/introduction and make it optional, but this is out of scope for Auth.js |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Environment
System:
OS: macOS 14.1
CPU: (10) arm64 Apple M1 Pro
Memory: 115.56 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
pnpm: 8.10.0 - ~/Library/pnpm/pnpm
Watchman: 2023.10.09.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 112.1.50.121
Chrome: 116.0.5845.187
Safari: 17.1
ALSO HAPPENS IN DOCKER
Reproduction URL
https://github.com/theopomies/self-hosted-nextjs
Describe the issue
I'm trying to make a reusable template for myself to self-host projects using Next, Docker, Drizzle, Postgres and NextAuth
When docker compose tries to build it hits parts of the codebase that require a DB connection, for example in
db/index.ts
, following the drizzle docs, I have the following:This code is referenced by NextAuth/Auth.js with
Itself referenced by an api route to create a 'protected' route and the default
/api/auth/[...nextauth]/route.ts
.During the build step, the 'db' service of my docker compose is not yet up, neither should it be, and so, the migration line and the api route raise errors, along with the fact that process.env.DATABASE_URL also doesn't exist (yet), as docker-compose injects env vars at runtime, not build time, but these lines, I suppose, shouldn't be referenced anyways.
The error looks like that:
How to reproduce
To reproduce, create a new Next.js 14 project, with drizzle-orm, next-auth@beta (v5) and Postgres.
Following the migration docs, create the auth.config.ts, auth.ts and middleware.ts files, the schema, and finally your API Route, based on the docs.
If you now try to build your project without the database being up (or simply by commenting your DATABASE_URL from your .env), you should encounter the same issue as I did, showing that with this setup, you need a valid database connection at build time (!)
Expected behavior
Database connection should not be required at build time, I suppose, or else I'd love to know the fix or my mistake, thanks!
Best,
Théo POMIES
Beta Was this translation helpful? Give feedback.
All reactions