Error Messages Reference
Complete guide to understanding and resolving Mifty error messages.
Installation Errors
EACCES Permission Denied
Error Message:
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules/@mifty/cli
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied
Cause: Insufficient permissions to install global npm packages.
Solutions:
-
Fix npm permissions (Recommended):
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules -
Use npx instead:
npx @mifty/cli init my-project -
Use Node Version Manager:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install node
npm install -g @mifty/cli
EADDRINUSE Port Already in Use
Error Message:
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1318:16)
Cause: Another process is using the specified port.
Solutions:
-
Find and kill the process:
# Find process using port 3000
lsof -ti:3000 | xargs kill -9 # macOS/Linux
netstat -ano | findstr :3000 # Windows -
Use a different port:
PORT=3001 npm run dev -
Update .env file:
PORT=3001
DB_DESIGNER_PORT=3002
Database Errors
Prisma Client Not Generated
Error Message:
PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "darwin".
Cause: Prisma client hasn't been generated after schema changes.
Solution:
npm run prisma:generate
Database Connection Failed
Error Message:
PrismaClientInitializationError: Can't reach database server at `localhost:5432`
Cause: Database server is not running or connection string is incorrect.
Solutions:
-
Check database service:
# PostgreSQL
brew services start postgresql # macOS
sudo systemctl start postgresql # Linux
# MySQL
brew services start mysql # macOS
sudo systemctl start mysql # Linux -
Verify connection string:
# PostgreSQL
DATABASE_URL="postgresql://username:password@localhost:5432/database"
# MySQL
DATABASE_URL="mysql://username:password@localhost:3306/database"
# PostgreSQL (default)
DATABASE_URL="postgresql://postgres:password@localhost:5432/mifty_dev"
Migration Failed
Error Message:
Error: P3009: migrate found failed migration file: 20231201000000_init/migration.sql
Cause: Previous migration failed and left the database in an inconsistent state.
Solutions:
-
Reset migrations (Development only):
npm run prisma:migrate:reset -
Mark migration as applied:
npm run prisma:migrate:resolve --applied 20231201000000_init -
Fix and retry migration:
# Edit the migration file to fix SQL errors
npm run prisma:migrate:dev
Foreign Key Constraint Failed
Error Message:
PrismaClientKnownRequestError: Foreign key constraint failed on the field: `authorId`
Cause: Trying to create a record with a foreign key that doesn't exist.
Solutions:
-
Check referenced record exists:
// ❌ Wrong - user might not exist
const post = await prisma.post.create({
data: {
title: "My Post",
authorId: "non-existent-id"
}
});
// ✅ Correct - verify user exists first
const user = await prisma.user.findUnique({ where: { id: userId } });
if (!user) throw new Error('User not found');
const post = await prisma.post.create({
data: {
title: "My Post",
authorId: userId
}
}); -
Use nested create:
const post = await prisma.post.create({
data: {
title: "My Post",
author: {
connect: { id: userId } // Will fail gracefully if user doesn't exist
}
}
});
TypeScript Compilation Errors
Cannot Find Module
Error Message:
TS2307: Cannot find module '@modules/user/user.service' or its corresponding type declarations.
Cause: TypeScript cannot resolve the module path.
Solutions:
-
Check tsconfig.json paths:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@modules/*": ["modules/*"],
"@services/*": ["services/*"],
"@/*": ["*"]
}
}
} -
Use relative imports:
// ❌ Absolute import might fail
import { UserService } from '@modules/user/user.service';
// ✅ Relative import is reliable
import { UserService } from '../user/user.service'; -
Restart TypeScript server:
- VS Code:
Ctrl+Shift+P→ "TypeScript: Restart TS Server"
- VS Code:
Circular Dependency Detected
Error Message:
TS6133: 'UserService' is declared but its value is never read.
Warning: Circular dependency detected:
src/modules/user/user.service.ts -> src/modules/post/post.service.ts -> src/modules/user/user.service.ts
Cause: Two or more modules import each other, creating a circular dependency.
Solutions:
-
Use dependency injection:
// ❌ Direct import creates circular dependency
import { PostService } from '../post/post.service';
@Injectable()
export class UserService {
constructor(private postService: PostService) {}
}
// ✅ Use forwardRef to break the cycle
import { forwardRef, Inject } from '@nestjs/common';
@Injectable()
export class UserService {
constructor(
@Inject(forwardRef(() => PostService))
private postService: PostService
) {}
} -
Extract shared interfaces:
// Create shared/interfaces.ts
export interface IUser {
id: string;
email: string;
}
// Both services import from interfaces instead of each other
Type Errors in Generated Code
Error Message:
TS2322: Type 'string | null' is not assignable to type 'string'.
Cause: Generated code doesn't match the database schema or Prisma types.
Solutions:
-
Regenerate Prisma client:
npm run prisma:generate -
Update db.design.ts:
// ❌ Nullable field without proper typing
{
name: "email",
type: "String",
isRequired: false // This makes it nullable
}
// ✅ Handle nullable types properly
{
name: "email",
type: "String",
isRequired: true // Or handle null in code
} -
Regenerate modules:
npm run generate
Runtime Errors
Module Generation Failed
Error Message:
Error: Failed to generate module 'User': Invalid table definition
at ModuleGenerator.generate (/path/to/generator.js:45:13)
Cause: Invalid table definition in db.design.ts.
Solutions:
-
Validate db.design.ts syntax:
npx tsc --noEmit src/db.design.ts -
Check for common issues:
// ❌ Missing required fields
{
name: "User",
columns: [
// Missing id field
{
name: "email",
type: "String"
}
]
}
// ✅ Complete table definition
{
name: "User",
columns: [
{
name: "id",
type: "String",
isPrimaryKey: true,
defaultValue: "cuid()"
},
{
name: "email",
type: "String",
isRequired: true,
isUnique: true
}
]
}
Import Resolution Failed
Error Message:
Error [ERR_MODULE_NOT_FOUND]: Cannot resolve module './non-existent-file'
Cause: Generated code references files that don't exist.
Solutions:
-
Clean and regenerate:
# Remove generated files
rm -rf src/modules/
# Regenerate
npm run generate -
Check file naming:
- Ensure table names use PascalCase
- Avoid TypeScript reserved words
- Use valid identifier names
Validation Errors
Error Message:
ValidationError: "email" is required
at Object.validate (/path/to/validation.js:12:11)
Cause: Request data doesn't match validation schema.
Solutions:
-
Check request body:
// ❌ Missing required field
const response = await fetch('/api/users', {
method: 'POST',
body: JSON.stringify({
name: "John Doe"
// Missing email field
})
});
// ✅ Include all required fields
const response = await fetch('/api/users', {
method: 'POST',
body: JSON.stringify({
name: "John Doe",
email: "john@example.com"
})
}); -
Update validation schema:
// If email should be optional, update the schema
const createUserSchema = z.object({
name: z.string(),
email: z.string().email().optional()
});
Development Server Errors
Hot Reload Failed
Error Message:
[nodemon] app crashed - waiting for file changes before starting...
Cause: TypeScript compilation error or runtime exception.
Solutions:
-
Check TypeScript errors:
npx tsc --noEmit -
Check for syntax errors:
npm run lint -
Restart development server:
# Stop server (Ctrl+C) and restart
npm run dev
Memory Limit Exceeded
Error Message:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Cause: Node.js ran out of memory during development.
Solutions:
-
Increase memory limit:
NODE_OPTIONS="--max-old-space-size=4096" npm run dev -
Add to package.json:
{
"scripts": {
"dev": "NODE_OPTIONS='--max-old-space-size=4096' ts-node-dev src/main.ts"
}
} -
Check for memory leaks:
- Look for infinite loops
- Check for large object accumulation
- Monitor memory usage
Testing Errors
Test Database Connection Failed
Error Message:
PrismaClientInitializationError: Can't reach database server during testing
Cause: Test database not configured or not running.
Solutions:
-
Set up test database:
# .env.test
DATABASE_URL="postgresql://postgres:password@localhost:5432/mifty_test"
NODE_ENV=test -
Initialize test database:
NODE_ENV=test npm run prisma:migrate:dev
NODE_ENV=test npm run prisma:generate -
Use in-memory database for tests:
DATABASE_URL="file::memory:?cache=shared"
Test Timeout
Error Message:
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout
Cause: Test takes longer than the default timeout.
Solutions:
-
Increase timeout for specific test:
it('should handle long operation', async () => {
// Increase timeout to 10 seconds
jest.setTimeout(10000);
const result = await longRunningOperation();
expect(result).toBeDefined();
}); -
Set global timeout:
// jest.config.js
module.exports = {
testTimeout: 10000 // 10 seconds
};
API Errors
Route Not Found
Error Message:
Cannot GET /api/v1/nonexistent
Cause: Requested route doesn't exist or module not properly registered.
Solutions:
-
Check route registration:
// app.module.ts
@Module({
imports: [
UserModule, // Ensure module is imported
PostModule
]
})
export class AppModule {} -
Verify controller routes:
@Controller('api/v1/users')
export class UserController {
@Get()
findAll() {
// This creates GET /api/v1/users
}
}
Validation Failed
Error Message:
{
"statusCode": 400,
"message": ["email must be an email"],
"error": "Bad Request"
}
Cause: Request data doesn't pass validation.
Solutions:
-
Check request format:
// ❌ Invalid email format
{
"email": "invalid-email",
"name": "John Doe"
}
// ✅ Valid email format
{
"email": "john@example.com",
"name": "John Doe"
} -
Update validation rules:
export class CreateUserDto {
@IsEmail()
@IsOptional() // Make email optional if needed
email?: string;
@IsString()
@IsNotEmpty()
name: string;
}
Deployment Errors
Build Failed
Error Message:
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! build script failed
Cause: TypeScript compilation errors or missing dependencies.
Solutions:
-
Check TypeScript errors:
npx tsc --noEmit -
Install dependencies:
npm ci # Clean install -
Check for missing environment variables:
NODE_ENV=production
DATABASE_URL=your-production-url
Production Runtime Error
Error Message:
Error: Cannot find module './dist/main.js'
Cause: Build output not found or incorrect start script.
Solutions:
-
Ensure build completed:
npm run build
ls -la dist/ # Check if files exist -
Check start script:
{
"scripts": {
"start": "node dist/main.js"
}
}
Getting Additional Help
Enable Verbose Logging
# Enable all debug output
DEBUG=* npm run dev
# Enable specific categories
DEBUG=mifty:* npm run dev
DEBUG=prisma:* npm run dev
Generate Error Report
# Collect system information
node --version
npm --version
mifty --version
# Check configuration
npm run config:validate
# Generate debug bundle
npm run debug:bundle
Common Error Patterns
| Error Pattern | Likely Cause | Quick Fix |
|---|---|---|
EACCES | Permission issues | sudo chown -R $(whoami) ~/.npm |
EADDRINUSE | Port conflict | Change port or kill process |
Cannot find module | Import path issues | Use relative imports |
Prisma*Error | Database issues | Regenerate client |
Validation*Error | Invalid request data | Check request format |
Timeout | Slow operations | Increase timeout |
💡 Pro Tip: Most errors can be resolved by ensuring you have the latest version of Mifty, clearing caches, and regenerating the Prisma client. When in doubt, try the "clean slate" approach: clear caches, reinstall dependencies, and regenerate all code.