# DBIS Source Code Fixes Applied **Date**: 2026-01-03 **Status**: ✅ **FIXES APPLIED** --- ## Problem Resolved **Issue**: API service failed with `MODULE_NOT_FOUND: Cannot find module '@shared/config/env'` **Root Cause**: TypeScript path aliases (`@shared/`, `@/core/`, etc.) were not resolved at runtime. Node.js cannot resolve these aliases without runtime support. --- ## Solution Applied **Method**: Solution 1 - Using `tsconfig-paths` package This solution: - Installs `tsconfig-paths` package for runtime path alias resolution - Creates `dist/index-runtime.js` entry point that registers path aliases before loading the app - Updates systemd service to use the runtime entry point --- ## Changes Applied ### VMID 10150 (API Primary) 1. ✅ **Installed tsconfig-paths**: ```bash cd /opt/dbis-core npm install --save tsconfig-paths ``` 2. ✅ **Created runtime entry point** (`/opt/dbis-core/dist/index-runtime.js`): ```javascript require("tsconfig-paths/register"); require("./index.js"); ``` 3. ✅ **Updated systemd service** (`/etc/systemd/system/dbis-api.service`): - Changed `ExecStart` from `dist/index.js` to `dist/index-runtime.js` - Reloaded systemd daemon - Restarted service ### VMID 10151 (API Secondary) 1. ✅ **Installed tsconfig-paths** 2. ✅ **Created runtime entry point** 3. ⏳ **Systemd service** - May need to be created if it doesn't exist --- ## Verification Steps ### Check Service Status ```bash # API Primary (10150) ssh root@192.168.11.10 "pct exec 10150 -- systemctl status dbis-api" # API Secondary (10151) - if service exists ssh root@192.168.11.10 "pct exec 10151 -- systemctl status dbis-api" ``` ### Check Logs ```bash # View recent logs ssh root@192.168.11.10 "pct exec 10150 -- journalctl -u dbis-api -n 50" # Follow logs in real-time ssh root@192.168.11.10 "pct exec 10150 -- journalctl -u dbis-api -f" ``` ### Test Health Endpoint ```bash curl http://192.168.11.155:3000/health ``` ### Verify Port Listening ```bash ssh root@192.168.11.10 "pct exec 10150 -- ss -tln | grep 3000" ``` --- ## Expected Results After applying these fixes: 1. ✅ Service should start without `MODULE_NOT_FOUND` errors 2. ✅ Application should load successfully 3. ✅ Port 3000 should be listening 4. ✅ Health endpoint should respond --- ## Next Steps If the service starts successfully: 1. **Test API endpoints** - Verify the API is responding correctly 2. **Run database migrations** - If needed: ```bash ssh root@192.168.11.10 "pct exec 10150 -- cd /opt/dbis-core && npx prisma migrate deploy" ``` 3. **Test Frontend connectivity** - Verify frontend can connect to API 4. **Monitor logs** - Check for any runtime errors --- ## Troubleshooting ### If Service Still Fails 1. **Check logs for specific errors**: ```bash ssh root@192.168.11.10 "pct exec 10150 -- journalctl -u dbis-api -n 100" ``` 2. **Verify tsconfig-paths is installed**: ```bash ssh root@192.168.11.10 "pct exec 10150 -- cd /opt/dbis-core && npm list tsconfig-paths" ``` 3. **Verify index-runtime.js exists**: ```bash ssh root@192.168.11.10 "pct exec 10150 -- cat /opt/dbis-core/dist/index-runtime.js" ``` 4. **Verify systemd service configuration**: ```bash ssh root@192.168.11.10 "pct exec 10150 -- cat /etc/systemd/system/dbis-api.service" ``` 5. **Try running manually** (for debugging): ```bash ssh root@192.168.11.10 "pct exec 10150 -- cd /opt/dbis-core && node dist/index-runtime.js" ``` ### Alternative Solutions If `tsconfig-paths` doesn't work, consider: 1. **Solution 2**: Use `tsc-alias` to rewrite paths during build 2. **Solution 3**: Create custom path resolver (more complex) --- ## Files Modified - `/opt/dbis-core/dist/index-runtime.js` (created) - `/etc/systemd/system/dbis-api.service` (updated - ExecStart path) - `/opt/dbis-core/package.json` (updated - added tsconfig-paths dependency) - `/opt/dbis-core/package-lock.json` (updated) --- ## Summary ✅ **Fix Applied**: TypeScript path alias resolution using `tsconfig-paths` ✅ **Containers Updated**: VMID 10150 (API Primary), VMID 10151 (API Secondary) ✅ **Service Updated**: Systemd service configured to use runtime entry point **Status**: Ready for testing. Service should now start without module resolution errors. --- **Last Updated**: 2026-01-03