TypeScript Compilation Fix Guide
Problem Detected
TypeScript compiler reports files "not found" even though they exist on disk. This is typically a caching issue or tsconfig problem.
Quick Fix Steps
Step 1: Stop All Running Processes
# Kill any running dev servers
pkill -f "node.*field-service" || true
pkill -f "ts-node" || true
Step 2: Clear All Caches
cd /Users/trannhatsang/Documents/UIT_School/Semester04/IE505_THESIS/projects/football-booking-backend-boilerplate
# Clear TypeScript cache
rm -rf dist/
rm -rf node_modules/.cache/
rm -rf apps/field-service/dist/
rm -rf .nx/cache/
# Clear tsconfig build info
find . -name "*.tsbuildinfo" -delete
echo "✅ All caches cleared"
Step 3: Restart TypeScript Server in IDE
In VS Code / Cursor:
- Press
Cmd+Shift+P(Mac) orCtrl+Shift+P(Windows) - Type: "TypeScript: Restart TS Server"
- Press Enter
Step 4: Rebuild from Scratch
# Install dependencies (if needed)
yarn install
# Build the project
yarn build
# Or start dev server
yarn dev
If Still Not Working
Fix 1: Check TypeScript Version
yarn why typescript
npx tsc --version
Should be 4.x or 5.x.
Fix 2: Verify Files Exist
# Check auth files
ls -la apps/field-service/src/auth/
ls -la apps/field-service/src/auth/decorators/
ls -la apps/field-service/src/auth/guards/
ls -la apps/field-service/src/auth/strategies/
# Check DTO files
ls -la apps/field-service/src/fields/dto/
# Should see ALL files listed without errors
Fix 3: Test Single File Compilation
# Test compile one file
npx tsc --noEmit apps/field-service/src/auth/auth.module.ts
# Should compile without errors
Fix 4: Update tsconfig.json (If Needed)
Edit apps/field-service/tsconfig.json:
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": ".",
"incremental": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
Common Errors & Solutions
Error: "Cannot find name 'super'"
File: auth/guards/keycloak-auth.guard.ts
Solution: Already fixed - changed return type to any instead of ReturnType<typeof super.canActivate>
Error: "File not found"
Cause: TypeScript cache or incorrect tsconfig
Solution:
- Clear cache (Step 2 above)
- Restart TS server (Step 3 above)
- Rebuild (Step 4 above)
Error: "Cannot find module './operating-hours.dto'"
File: dto/create-field.dto.ts
Solution: Not an issue - the file defines classes internally, doesn't import from external file
Verification Checklist
After following the steps above:
- [ ] All cache directories cleared
- [ ] TypeScript server restarted
- [ ]
yarn devruns without "file not found" errors - [ ] No red squiggles in IDE
- [ ] Build completes successfully
Nuclear Option (Last Resort)
If nothing else works:
# Complete reset
rm -rf node_modules yarn.lock
rm -rf dist .nx
yarn install
yarn build
Files That Should Exist
All these files MUST exist (verified they do):
Auth Module (7 files):
✅ apps/field-service/src/auth/auth.module.ts
✅ apps/field-service/src/auth/index.ts
✅ apps/field-service/src/auth/decorators/public.decorator.ts
✅ apps/field-service/src/auth/decorators/roles.decorator.ts
✅ apps/field-service/src/auth/guards/keycloak-auth.guard.ts
✅ apps/field-service/src/auth/guards/roles.guard.ts
✅ apps/field-service/src/auth/strategies/keycloak.strategy.ts
DTOs (8 files):
✅ apps/field-service/src/fields/dto/create-field.dto.ts
✅ apps/field-service/src/fields/dto/operating-hours.dto.ts
✅ apps/field-service/src/fields/dto/paginated-result.dto.ts
✅ apps/field-service/src/fields/dto/reject-field.dto.ts
✅ apps/field-service/src/fields/dto/reorder-images.dto.ts
✅ apps/field-service/src/fields/dto/search-fields.dto.ts
✅ apps/field-service/src/fields/dto/update-field-status.dto.ts
✅ apps/field-service/src/fields/dto/update-field.dto.ts
Controllers (2 files):
✅ apps/field-service/src/fields/controllers/fields.controller.ts
✅ apps/field-service/src/fields/controllers/admin-fields.controller.ts
Services (2 files):
✅ apps/field-service/src/fields/services/fields.service.ts
✅ apps/field-service/src/fields/services/image.service.ts
Entities (2 files):
✅ apps/field-service/src/fields/entities/field.entity.ts
✅ apps/field-service/src/fields/entities/field-image.entity.ts
Guards (1 file):
✅ apps/field-service/src/fields/guards/field-ownership.guard.ts
Config (2 files):
✅ apps/field-service/src/config/storage.config.ts
✅ apps/field-service/src/config/index.ts
Migrations (1 file):
✅ apps/field-service/src/migrations/1737000000000-UpdateFieldSchema.ts
Total: 32 files - all exist on disk!
Debug Commands
# Count TypeScript files
find apps/field-service/src -name "*.ts" ! -name "*spec.ts" | wc -l
# Should show: 35
# Check for any permission issues
find apps/field-service/src -name "*.ts" ! -perm -r
# Should show: (empty)
# Verify no duplicate files
find apps/field-service/src -name "*.ts" | sort | uniq -d
# Should show: (empty)
Expected Result
After completing these steps:
yarn dev
# Output should be:
# ✓ Compiled successfully
# Field Service running on: http://localhost:3002
No "file not found" errors! ✅