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.viewModel

  • Examine 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:

  1. Check for unclosed HTML tags

  2. Verify custom element imports

  3. Ensure proper binding syntax

Binding Failures

Issue: Properties not updating in the view

Debug steps:

  1. Check property observability:

  1. Verify binding mode:

Custom Element Issues

Issue: Custom element not recognized

Solutions:

  1. Verify import and registration:

  1. Check naming conventions:

Memory Leaks

Issue: Components not being garbage collected

Solutions:

  1. Properly dispose of subscriptions:

  1. Remove event listeners:

Performance Debugging

Component Rendering Performance

Use Chrome DevTools Performance tab:

  1. Record performance during navigation

  2. Look for long tasks and forced reflows

  3. Identify component lifecycle bottlenecks

Binding Expression Performance

Debug slow binding expressions:

Memory Usage Analysis

Monitor memory usage in DevTools:

  1. Use Memory tab to take heap snapshots

  2. Compare snapshots to identify leaks

  3. Look for detached DOM nodes

Build and Bundler Issues

Webpack Issues

Issue: Module resolution errors

Debug steps:

  1. Check resolve configuration:

  1. Verify loader order:

Vite Issues

Issue: Import resolution problems

Solutions:

  1. Check Vite configuration:

  1. 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?.name

  • Add 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

  1. Start Small: Isolate issues to the smallest possible scope

  2. Use Logging: Implement comprehensive logging throughout your app

  3. Reproduce Consistently: Create reliable reproduction steps

  4. Check Dependencies: Verify all service registrations and imports

  5. Use TypeScript: Catch errors at compile time

Development Workflow

  1. Enable all development features (source maps, logging, dev bundles)

  2. Use browser developer tools effectively

  3. Write unit tests for complex logic

  4. Monitor performance regularly

  5. Set up error tracking for production

Error Prevention

  1. Use TypeScript strict mode

  2. Implement proper error boundaries

  3. Validate inputs and handle edge cases

  4. Use defensive programming techniques

  5. 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?