Debugging & Troubleshooting
A comprehensive guide to debugging Aurelia 2 applications, troubleshooting common issues, and using development tools effectively.
Effective debugging is crucial for developing robust Aurelia applications. This guide covers debugging strategies, common issues, development tools, and troubleshooting techniques specifically for Aurelia 2.
Table of Contents
Development Environment Setup
Enable Development Mode
Always use development builds during development for better debugging experience:
// main.ts
import { Aurelia, LogLevel } from 'aurelia';
const au = new Aurelia();
// Configure logging for development
if (process.env.NODE_ENV !== 'production') {
au.register(LoggingConfiguration.customize(options => {
options.level = LogLevel.debug;
options.colorOptions = ColorOptions.colors;
}));
}
au.app(component).start();Source Maps Configuration
Ensure proper source map configuration for accurate debugging:
Webpack:
Vite:
Development Aliases
Use development bundles for better debugging:
Browser Developer Tools
Chrome DevTools Extensions
While there's no official Aurelia 2 extension yet, you can use general debugging techniques:
Elements Panel
Inspect custom elements and their properties
View component instances via
$0.au.controller.viewModelExamine binding contexts and scopes
Console Debugging
Access component instances directly:
Sources Panel
Set breakpoints in TypeScript source (with source maps)
Use conditional breakpoints for specific scenarios
Step through component lifecycle methods
Firefox Developer Tools
Similar debugging capabilities with excellent source map support:
Aurelia-Specific Debugging
Component Lifecycle Debugging
Add logging to component lifecycle methods:
Binding Expression Debugging
Debug binding expressions with logging:
Create a debug value converter:
Dependency Injection Debugging
Debug DI resolution issues:
Router Debugging
Enable router debugging:
Add router event listeners:
Common Issues and Solutions
Template Compilation Errors
Issue: Template fails to compile
Solutions:
Check for unclosed HTML tags
Verify custom element imports
Ensure proper binding syntax
Binding Failures
Issue: Properties not updating in the view
Debug steps:
Check property observability:
Verify binding mode:
Custom Element Issues
Issue: Custom element not recognized
Solutions:
Verify import and registration:
Check naming conventions:
Memory Leaks
Issue: Components not being garbage collected
Solutions:
Properly dispose of subscriptions:
Remove event listeners:
Performance Debugging
Component Rendering Performance
Use Chrome DevTools Performance tab:
Record performance during navigation
Look for long tasks and forced reflows
Identify component lifecycle bottlenecks
Binding Expression Performance
Debug slow binding expressions:
Memory Usage Analysis
Monitor memory usage in DevTools:
Use Memory tab to take heap snapshots
Compare snapshots to identify leaks
Look for detached DOM nodes
Build and Bundler Issues
Webpack Issues
Issue: Module resolution errors
Debug steps:
Check resolve configuration:
Verify loader order:
Vite Issues
Issue: Import resolution problems
Solutions:
Check Vite configuration:
Verify file extensions in imports:
Runtime Error Patterns
Common Error Messages
"Cannot read property of undefined"
Check for null/undefined values in bindings
Use safe navigation:
user?.profile?.nameAdd null checks in computed properties
"Cyclic dependency detected"
Review service dependencies
Use factory patterns or lazy injection
Break circular references
"No matching constructor"
Check dependency injection setup
Verify service registration
Ensure proper imports
Error Boundary Pattern
Create error boundary components:
Testing and Debugging
Unit Test Debugging
Debug unit tests with proper setup:
Integration Test Debugging
Use browser debugging for integration tests:
Advanced Debugging Techniques
Custom Debug Panel
Create a development-only debug panel:
Performance Monitoring
Add performance monitoring:
Network Request Debugging
Monitor and debug HTTP requests:
Best Practices
Debugging Strategy
Start Small: Isolate issues to the smallest possible scope
Use Logging: Implement comprehensive logging throughout your app
Reproduce Consistently: Create reliable reproduction steps
Check Dependencies: Verify all service registrations and imports
Use TypeScript: Catch errors at compile time
Development Workflow
Enable all development features (source maps, logging, dev bundles)
Use browser developer tools effectively
Write unit tests for complex logic
Monitor performance regularly
Set up error tracking for production
Error Prevention
Use TypeScript strict mode
Implement proper error boundaries
Validate inputs and handle edge cases
Use defensive programming techniques
Regular code reviews focusing on error scenarios
Conclusion
Effective debugging in Aurelia 2 requires understanding the framework's architecture, using appropriate tools, and following systematic troubleshooting approaches. By implementing the techniques and strategies outlined in this guide, you'll be able to identify and resolve issues more efficiently, leading to more robust and maintainable applications.
Remember that good debugging practices start with good development practices—clear code structure, comprehensive testing, and proper error handling will prevent many issues before they become debugging challenges.
Last updated
Was this helpful?