bun-server-troubleshooting
1
总安装量
1
周安装量
#49925
全站排名
安装命令
npx skills add https://github.com/dangaogit/bun-server-skills --skill bun-server-troubleshooting
Agent 安装分布
trae
1
qoder
1
trae-cn
1
claude-code
1
Skill 文档
Bun Server Troubleshooting
Dependency Injection Issues
“Parameter type is undefined” Error
Symptom:
Error: Cannot resolve dependency at index 0 of MyController.
Parameter type is undefined. Use @Inject() decorator to specify the dependency type.
Causes:
- Missing
tsconfig.jsonconfiguration - Monorepo root missing
tsconfig.json - Debug plugin not reading
tsconfig.json
Solution:
Ensure tsconfig.json includes:
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
For monorepo projects, add tsconfig.json to root directory.
Workaround: Use explicit @Inject():
constructor(@Inject(UserService) private userService: UserService) {}
“Provider not found for token” Error
Symptom:
Error: Provider not found for token: Symbol(@dangao/bun-server:events:emitter)
Cause: Module requiring forRoot() was not configured.
Solution:
// â Wrong
@Module({
imports: [EventModule],
})
// â
Correct
@Module({
imports: [EventModule.forRoot({ wildcard: true })],
})
EventModule Issues
@OnEvent Decorator Not Working
Cause: Event listeners not initialized.
Solution: Call initializeListeners after registerModule:
import { Application, EventModule, ModuleRegistry } from "@dangao/bun-server";
const app = new Application({ port: 3100 });
app.registerModule(AppModule);
// Initialize event listeners
const rootModuleRef = ModuleRegistry.getInstance().getModuleRef(AppModule);
if (rootModuleRef?.container) {
EventModule.initializeListeners(
rootModuleRef.container,
[NotificationListener, AuditListener], // All @OnEvent classes
);
}
app.listen();
Application Startup Issues
Module Configuration Order
Problem: Child modules fail to resolve dependencies.
Solution: Configure forRoot() before module definitions:
// â
Configure first
EventModule.forRoot({ wildcard: true });
LoggerModule.forRoot({ level: LogLevel.INFO });
// Then define modules
@Module({
imports: [EventModule],
providers: [UserService],
})
class UserModule {}
Circular Dependencies
Symptom: Stack overflow or undefined services.
Solution: Use forwardRef:
@Injectable()
class ServiceA {
constructor(
@Inject(forwardRef(() => ServiceB)) private b: ServiceB
) {}
}
Debug Techniques
Verify Decorator Metadata
import "reflect-metadata";
// Check if paramtypes are generated
console.log(
"paramTypes:",
Reflect.getMetadata("design:paramtypes", YourController)
);
// Expected: [class ServiceA, class ServiceB, ...]
// Problem: undefined or []
Debug Container Resolution
const container = app.getContainer();
// List all registered providers
console.log("Providers:", container.getProviders());
// Try manual resolution
try {
const service = container.resolve(UserService);
console.log("Resolved:", service);
} catch (error) {
console.error("Resolution failed:", error);
}
Debug Module References
import { ModuleRegistry } from "@dangao/bun-server";
const moduleRef = ModuleRegistry.getInstance().getModuleRef(AppModule);
console.log("Module container:", moduleRef?.container);
console.log("Module metadata:", moduleRef?.metadata);
Common Mistakes
Forgetting @Injectable
// â Missing decorator
class UserService {
getUser() { return {}; }
}
// â
Correct
@Injectable()
class UserService {
getUser() { return {}; }
}
Using import type with Symbol+Interface Pattern
// â Wrong - type-only import removes Symbol at runtime
import type { UserService } from "./user.service";
// â
Correct - keeps both interface and Symbol
import { UserService } from "./user.service";
Not Exporting from Module
// â Service not accessible to other modules
@Module({
providers: [SharedService],
})
class SharedModule {}
// â
Export to make available
@Module({
providers: [SharedService],
exports: [SharedService],
})
class SharedModule {}
Debugging Checklist
-
tsconfig.jsonhasexperimentalDecorators: true -
tsconfig.jsonhasemitDecoratorMetadata: true - Services have
@Injectable()decorator - Modules using
forRoot()are configured before definitions - Services are registered in module
providers - Required services are in module
exports - Event listeners call
EventModule.initializeListeners()