Troubleshooting
Solutions to common issues when developing with VeloxTS.
Prisma 7 Issues
Section titled “Prisma 7 Issues””Unknown property datasourceUrl”
Section titled “”Unknown property datasourceUrl””Error:
Unknown property datasourceUrl in PrismaClient constructorCause: Prisma 7 removed datasourceUrl and datasources options.
Solution: Use a driver adapter instead:
// Before (Prisma 5/6)const db = new PrismaClient({ datasourceUrl: process.env.DATABASE_URL,});
// After (Prisma 7)import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
const adapter = new PrismaBetterSqlite3({ url: process.env.DATABASE_URL });const db = new PrismaClient({ adapter });“Generating into @prisma/client not allowed”
Section titled ““Generating into @prisma/client not allowed””Cause: Wrong output path in schema.prisma.
Solution: Use .prisma/client:
generator client { provider = "prisma-client-js" output = "../node_modules/.prisma/client" // Correct}Database URL Not Loading
Section titled “Database URL Not Loading”Cause: Vite SSR doesn’t auto-load .env files.
Solution: Load dotenv explicitly:
import dotenv from 'dotenv';import { dirname, resolve } from 'path';import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));dotenv.config({ path: resolve(__dirname, '..', '.env') });Type Errors
Section titled “Type Errors””Type ‘unknown’ is not assignable to…”
Section titled “”Type ‘unknown’ is not assignable to…””Cause: Context type not extended properly.
Solution: Ensure declaration merging is set up:
import '@veloxts/core';
declare module '@veloxts/core' { interface BaseContext { db: PrismaClient; user?: User; }}“Property ‘user’ does not exist on ctx”
Section titled ““Property ‘user’ does not exist on ctx””Cause: Auth plugin not registered or types not extended.
Solution:
- Register the auth plugin
- Add type declaration for
user
// 1. Register pluginapp.use(authPlugin({ userLoader: loadUser }));
// 2. Extend typesdeclare module '@veloxts/core' { interface BaseContext { user?: { id: string; email: string; role: string }; }}REST API Issues
Section titled “REST API Issues”Wrong HTTP Method Generated
Section titled “Wrong HTTP Method Generated”Cause: Procedure name doesn’t match REST conventions.
Solution: Use correct naming prefixes:
| Prefix | Method | Example |
|---|---|---|
get* | GET | getUser → GET /users/:id |
list* | GET | listUsers → GET /users |
create* | POST | createUser → POST /users |
update* | PUT | updateUser → PUT /users/:id |
delete* | DELETE | deleteUser → DELETE /users/:id |
Or override with .rest():
myProcedure: procedure() .rest({ method: 'POST', path: '/custom/path' }) .mutation(/* ... */)Route Not Found (404)
Section titled “Route Not Found (404)”Checklist:
- Is the router registered with the app?
- Is the procedure exported correctly?
- Is the base path correct (
/api)? - Check exact path in logs when server starts
// Verify router registrationapp.use(router);
// Check startup logs for registered routes// [INFO] GET /api/users// [INFO] POST /api/usersAuthentication Issues
Section titled “Authentication Issues””jwt malformed” or “invalid signature”
Section titled “”jwt malformed” or “invalid signature””Causes:
- Token corrupted in transmission
- Wrong secret used
- Token from different environment
Solution:
- Verify
JWT_SECRETmatches between token generation and verification - Check token isn’t truncated (copy full token)
- Ensure same secret across all instances
Guards Not Working
Section titled “Guards Not Working”Cause: Guard not applied or userLoader not returning expected fields.
Checklist:
- Is the guard applied to the procedure?
- Is
userLoaderreturning the fields your guard checks?
// Guard checks roleconst adminGuard = defineGuard({ name: 'admin', check: (ctx) => ctx.user?.role === 'admin', // Needs role field});
// userLoader must return roleconst userLoader = async (userId: string) => { return db.user.findUnique({ where: { id: userId }, select: { id: true, email: true, role: true }, // Include role! });};Build Issues
Section titled “Build Issues””Cannot find module ‘@veloxts/…’”
Section titled “”Cannot find module ‘@veloxts/…’””Causes:
- Dependencies not installed
- Wrong package version
Solution:
# Reinstall dependenciesrm -rf node_modules pnpm-lock.yamlpnpm install
# Verify versions matchpnpm list @veloxts/core @veloxts/routerTypeScript Compilation Errors
Section titled “TypeScript Compilation Errors”Common fixes:
- Clear TypeScript cache:
rm -rf node_modules/.cache - Restart TypeScript server in your editor
- Ensure
tsconfig.jsonextends the correct base config
HMR Issues
Section titled “HMR Issues”Changes Not Reloading
Section titled “Changes Not Reloading”Checklist:
- Is HMR enabled? (
velox devnotvelox dev --no-hmr) - Are boundaries configured in
package.json?
{ "hotHook": { "boundaries": [ "src/procedures/**/*.ts", "src/schemas/**/*.ts" ] }}Port Already in Use
Section titled “Port Already in Use”Error: EADDRINUSE: address already in use :::3030
Solution:
# Find process using portlsof -i :3030
# Kill itkill -9 <PID>
# Or use a different portvelox dev --port 4000Database Connection Issues
Section titled “Database Connection Issues”Connection Pool Exhausted
Section titled “Connection Pool Exhausted”Symptoms: Slow queries, timeouts, “too many connections”
Solutions:
- Add graceful shutdown handler:
const shutdown = async () => { await prisma.$disconnect(); process.exit(0);};
process.on('SIGTERM', shutdown);process.on('SIGINT', shutdown);- Configure connection pool:
DATABASE_URL=postgresql://...?connection_limit=10Getting Help
Section titled “Getting Help”If your issue isn’t covered here:
- Search existing issues: GitHub Issues
- Check the guides: Review relevant documentation sections
- Open an issue: Provide error message, code sample, and environment details