Troubleshooting & FAQ
This section provides solutions to common issues you might encounter.
๐ 1. Deployment Errors (Render)
๐ง Config validation error
-
๐จ Error:
Config validation error: [ "Admin email must be a valid email address", ... ] -
๐ง Cause: The application requires environment variables (defined in
src/config/config.ts) that are missing in the Render environment. -
โ Solution: Navigate to your Render Dashboard > Environment. Instead of uploading a
.envfile, copy the contents of your local.envfile and paste them directly into the "Environment Variables" bulk editor.
๐ฆ Module not found (seed.js)
-
๐จ Error:
MODULE_NOT_FOUND / Cannot find module .../seed.js -
๐ง Cause: The build script did not compile the
seed.tsfile, or the Dockerfile did not copy the compiled output. -
โ Solution: Ensure your
package.jsonbuild script includes the command to compile the seed file and that yourDockerfilecopies thedistfolder.title="package.json" "scripts": { "build": "tsc && tsc prisma/seed.ts" }title="Dockerfile" COPY --from=builder /app/dist ./dist(Note: This is already correctly configured in this template).
โ Command not found: prisma
-
๐จ Error:
Command not found: prisma(in Production logs) -
๐ง Cause: The
prismaCLI is typically a development dependency (devDependency), but it is required in the production environment to run database migrations. -
โ Solution: Move
"prisma"fromdevDependenciestodependenciesin yourpackage.jsonfile.
๐ณ 2. Docker & Local Development Errors
๐ Issues Running the App Locally
-
๐จ Error: Application fails to start with errors like
ECONNREFUSED,Can't reach database server, or other Prisma-related issues when runningnpm run dev:watch:local. -
๐ง Cause: This typically happens for one of two reasons:
- The required background services (Database, Redis) are not running.
-
The Prisma Client is not generated or the database schema is out of date.
-
โ Solution: A detailed guide for local development setup and troubleshooting is available in the Getting Started documentation.
Quick Checklist:
1. Are the database and Redis running? Before starting the app, you must run npm run docker:redis:postgres:up.
2. Is Prisma up to date? If the database is running but you still have errors, run these commands in order:
# 1. Regenerate the Prisma Client
npm run prisma:generate
# 2. Apply latest database migrations
npm run prisma:migrate:dev
npm run dev:watch:local.
๐ PrismaClientInitializationError
-
๐จ Error:
PrismaClientInitializationError: Can't reach database server at dummy:5432 -
๐ง Cause: The Docker image "baked in" the dummy
DATABASE_URLprovided during the build phase. The application is trying to connect to this dummy URL at runtime instead of the actual database URL. -
โ Solution: Never set
ENV DATABASE_URLin theDockerfile. Only pass it inline during the build process.title="Dockerfile" # Correct: Pass as an argument during build RUN DATABASE_URL="dummy" npm install # Incorrect: Do not set it as a permanent environment variable # ENV DATABASE_URL="dummy"
๐ Invalid depends_on format
-
๐จ Error:
services.app.depends_on.0 must be a string -
๐ง Cause: This error occurs when using an older, legacy syntax for
docker-compose.ymlfiles. -
โ Solution: Remove the
version: '3.8'(or similar) line from the top of yourdocker-compose.ymlfiles.
๐ Git error in Docker container
-
๐จ Error:
The process '/usr/bin/git' failed with exit code 128 -
๐ง Cause: Husky git hooks are attempting to run inside a Docker container where a
.gitdirectory does not exist. -
โ Solution: Disable Husky by setting the
HUSKYenvironment variable to0.DockerfileENV HUSKY=0
โ๏ธ 3. API & Runtime Errors
๐ฆ 429 Too Many Requests on Health Check
-
๐จ Error:
429 Too Many Requestson the health check endpoint (/api/v1/health). -
๐ง Cause: The hosting provider's load balancer is sending frequent requests to the health check endpoint, triggering the API's rate limiter.
-
โ Solution: In
src/server.ts, define the health check route before the global rate limiter middleware is applied.src/server.ts// Health check endpoint (before rate limiter) app.get('/api/v1/health', (_req, res) => { res.send('OK'); }); // Apply rate limiter to all subsequent routes app.use(limiter);
๐ Swagger UI requests failing in production
-
๐จ Error: Swagger UI or OpenAPI documentation requests fail (e.g., point to
localhost). -
๐ง Cause: The OpenAPI specification (
swaggerDef.ts) has a hardcoded server URL. -
โ Solution: In your OpenAPI definition file, change the server URL to a relative path (
/).src/docs/swaggerDef.tsconst swaggerDef = { // ... servers: [ { url: '/', // Use a relative path }, ], };
๐ Static files returning 404
-
๐จ Error: Static files (e.g.,
socket.ioclient) return a404 Not Founderror. -
๐ง Cause: When TypeScript is compiled, relative paths like
'../public'become incorrect. -
โ Solution: Use
path.join(__dirname, '../public')for a robust path and ensure yourDockerfilecopies thepublicfolder.src/server.tsimport path from 'path'; app.use(express.static(path.join(__dirname, '../public')));DockerfileCOPY public ./public
๐งฉ Prisma Client 'User' type not found
-
๐จ Error:
Module '@prisma/client' has no exported member 'User'. -
๐ง Cause: The Prisma Client (
@prisma/client) has not been generated or updated based on yourschema.prismafile. -
โ Solution: Run
npx prisma generateand restart your IDE or TypeScript server.npx prisma generate
## ๐งช 4. Testing Errors
### โก PrismaClientKnownRequestError in Tests
-
๐จ Error:
PrismaClientKnownRequestError: An operation failed because it depends on one or more records that were required but not found. -
๐ง Cause: This error often occurs when running tests (
npm test) if the test database is not in sync with the Prisma schema. The test setup might be trying to access or manipulate data that doesn't match the expected structure. -
โ Solution: Reset and re-apply your database migrations for the test environment. This ensures the test database schema is up-to-date.
npm run prisma:migrate:dev