Replies: 2 comments
-
|
Do you have verbose logging, and are you able to navigate the deployed image through sh? When you say it works locally, do you also mean next build + start? How do you connect to the DB? Is the path correct? You might have to use |
Beta Was this translation helpful? Give feedback.
-
|
This is a very common issue with SQLite + Docker! The problem is almost certainly the database file path. When running locally, your SQLite db resolves relative to your project root. Inside a Docker container, the working directory and filesystem are different — so Fix 1: Use an absolute path with a volume mount (recommended) In your docker-compose, mount a volume: volumes:
- ./data/roster.db:/app/data/roster.dbThen in your code: import Database from 'better-sqlite3';
import path from 'path';
const db = new Database(path.join(process.cwd(), 'data', 'roster.db'));Fix 2: Use an environment variable for the path const db = new Database(process.env.DB_PATH || path.join(process.cwd(), 'roster.db'));Then pass Why the error looks unrelated: Next.js catches the DB init failure silently and the crash surfaces later when code tries to use the You do NOT need to switch databases — SQLite works perfectly fine in Docker as long as the file path is correct and persisted via a volume. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hello
As part of teaching myself nextjs, I wrote a small roster app for a group I help manage. It's mostly mugshot + name and title.
Those are stored in a small better-sqlite3 db located at the root of my project, and accessed when needed through functions stored in a library file.
This works well enough in local (including running the actual docker image), but upon deploying a container image on my self hosted nginx server, I'm getting this on accessing the app:
⨯ TypeError: Cannot read properties of undefined (reading 'id') at h (.next/server/chunks/ssr/_39c43809._.js:12:591) { digest: '2257150320' }I am
From some cursory research I've done, I'm led to thinking that it may be due to the nature of a sqlite db and how it works with a docker container. Is there something I either need to do add in my dockerfile, or do I need to switch to a different type of db altogether?
Thanks in advance.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions