Troubleshooting
Backend won’t start
Symptom: Error: Cannot find module '@/app/...' or similar on pnpm backend:dev.
Cause: Path aliases not resolved or tsconfig.json paths not matching.
Fix: Verify tsconfig.json at backend-js/ has "@/*": ["./src/*"] under compilerOptions.paths. If missing, check that backend-js/tsconfig.json extends the correct base.
Missing or undefined environment variables
Symptom: undefined values in logs, DB connect errors, email send errors, JWT errors like secretOrPrivateKey must have a value.
Fix:
- Copy
.env.exampleto.env.localinbackend-js/. - Fill in all values — do not leave anything as-is from the example.
- Restart the dev server after changes.
Critical vars that have hardcoded fallbacks (unsafe in prod, but will silently work in dev):
JWT_SECRET— uses known fallback if unsetDEFAULT_USER_PASSWORD— uses known fallback if unset
Vars with no fallback that will crash at runtime:
RESEND_API_KEY— email send will failGOOGLE_DIRECTIONS_API_KEY— geocoding and route optimization will fail- MySQL vars — DB pool will fail at first query
Database connection errors
Symptom: ECONNREFUSED, ER_ACCESS_DENIED_ERROR, or Unknown database at runtime.
Checklist:
- MySQL server is running on
MYSQL_HOST:MYSQL_PORT. MYSQL_USER/MYSQL_PASSWORDcredentials are correct.- The database exists.
schema.sqlcreates it aserronka— runCREATE DATABASE IF NOT EXISTS erronkaif needed. MYSQL_DATABASEenv var matches the actual database name (erronkavspakag— they differ betweenschema.sqland.env.example).- SSL setting:
backend-js/src/app/config/dbConfig.tssetsssl: { rejectUnauthorized: false }. If your MySQL instance requires a specific cert, adjust this.
TypeScript check fails (tsc --noEmit errors)
Symptom: Type errors when running pnpm tsc --noEmit in backend-js/.
Common causes and fixes:
| Error | Fix |
|---|---|
Property 'X' does not exist on type 'Y' | Check that the DTO interface and the types file are in sync |
Argument of type 'any' is not assignable | No any allowed — add an explicit interface |
Cannot find module '@/app/...' | Check tsconfig.json paths |
Type error in route.ts | Verify requireAuth return type is used correctly |
401 on every request after login
Symptom: Login succeeds (returns access_token), but subsequent API calls return 401.
Checklist:
- The frontend is storing the access token correctly in the
access_tokencookie. - The Axios request interceptor is reading from the cookie and setting
Authorization: Bearer <token>. - The token isn’t expired — access token lifetime is 15 minutes.
- The backend is on a different origin — check CORS config and
withCredentials: true.
Refresh token not working / user repeatedly kicked to login
Symptom: User is logged out after 15 minutes despite SessionKeepAlive being active.
Checklist:
- Open DevTools → Application → Cookies. Confirm
refresh_tokencookie exists withHttpOnlyflag. - Confirm
POST /api/auth/refreshis not blocked by CORS. In dev, backend must allow the frontend origin withcredentials: true. - Confirm the refresh token row is not revoked/expired in the
tokenstable. - Check clock skew — if server time and client time differ by more than the token lifetime, tokens may appear expired immediately.
- Confirm
withCredentials: trueis set in the Axios client.
CORS errors
Symptom: Access-Control-Allow-Origin header missing, preflight fails.
Fix: In backend-js/next.config.ts (or equivalent CORS middleware), ensure:
- The frontend origin is allowed explicitly (not
*when using credentials). Access-Control-Allow-Credentials: trueis set.- Preflight
OPTIONSrequests return 200.
In production, both apps must be on HTTPS for SameSite=None; Secure cookies to work.
Email not sent after package creation / status change
Symptom: No email arrives, but the operation succeeds.
Checklist:
RESEND_API_KEYis set and valid.- The sender domain (
no-reply@tolosaerronka.es) is verified in Resend. - Check Resend dashboard for send failures or bounces.
- Status change emails are conditional — only specific transitions trigger emails. See Domain Model for the email trigger table.
Route creation fails (Google Maps error)
Symptom: POST /api/routes/create returns 500 or an error related to Directions API.
Checklist:
GOOGLE_DIRECTIONS_API_KEYis set and the key has Directions API and Geocoding API enabled in Google Cloud Console.- Billing is active on the Google Cloud project.
- The API key has no IP/referer restriction that blocks the backend server IP.
- Package addresses were geocoded successfully on creation — if
latitude/longitudeare 0 or NULL, geocoding failed at package creation time.
Geocoding returns wrong location
Symptom: Package appears at wrong coordinates on the map.
Cause: Google Geocoding matched a different address, or the address is ambiguous.
Fix: Check the package’s addresses row in the DB. Correct latitude/longitude manually if needed via a direct DB update (no endpoint currently exposes raw coordinate editing).
Route optimization exceeds max stops
Symptom: Route creation is rejected even with fewer packages than expected.
Cause: The route service adds carryover packages (assigned packages from previous days for the same distributor) to the stop list automatically. Total stops are capped at 20.
Fix: Reduce package_ids in the request to leave room for carryover, or clear the distributor’s backlog first.
Package status log missing after update
Symptom: GET /api/logs/listByPackage returns no logs after updateStatus call.
Cause: Log insertion happens in packageStatusSideEffects.service.ts. If it throws and is caught silently, the status update may succeed but no log is written.
Fix: Check backend console for errors from [packageStatusSideEffects]. Verify DB constraints allow the log insert (e.g., changed_by user exists).
Frontend build fails
Symptom: pnpm frontend:dev errors with TypeScript or module errors.
Fix:
# From monorepo root:
pnpm install # re-sync workspace deps
pnpm --filter @repo/frontend-app tsc --noEmit # isolate TS errorsDocs site search not finding a page
Symptom: Ctrl+K search returns no results for a known page.
Cause: Search is static and based on navItems titles in docs/app/[lang]/layout.tsx. If you add a new page without adding it to navItems, it won’t appear in search.
Fix: Add the new page to navItems in layout.tsx and update all three i18n dictionaries. See Docs Audit for the full procedure.
pnpm version conflicts
Symptom: ERR_PNPM_WORKSPACE_PKG_NOT_FOUND or workspace script not found.
Fix:
pnpm install # from monorepo rootAll workspace package commands must be run from the monorepo root using -filter flags or the root-level scripts in package.json.