Troubleshooting

This guide covers common issues you may encounter when implementing SSR with Aurelia and their solutions.

Common Setup Issues

Build Errors

Error: "Cannot resolve 'aurelia-pal'"

Symptoms:

Module not found: Error: Can't resolve 'aurelia-pal' in '/path/to/project'

Solution: Ensure you have installed the Node.js PAL package:

npm install aurelia-pal-nodejs

And initialize it in your server entry point:

import { initialize } from 'aurelia-pal-nodejs';
initialize();

Error: "aurelia-bootstrapper not found"

Symptoms:

Module not found: Error: Can't resolve 'aurelia-bootstrapper'

Solution: This usually happens when webpack is trying to load the client bootstrapper on the server. Ensure your server configuration uses the correct entry point:

// Server webpack config
{
  entry: './src/server-main.ts', // Not aurelia-bootstrapper
  target: 'node'
}

Runtime Errors

Error: "window is not defined"

Symptoms:

Cause: Your code is trying to access browser globals in the server environment.

Solution:

  1. Use environment checks:

  1. Use PAL abstractions:

Error: "document is not defined"

Symptoms:

Solution: Replace direct DOM access with PAL:

Error: "localStorage is not defined"

Symptoms:

Solution: Add environment checks or provide server-side alternatives:

Memory and Performance Issues

Memory Leaks

Symptoms:

  • Server memory usage continuously increases

  • Server becomes unresponsive over time

  • "Out of memory" errors

Debugging Memory Leaks:

  1. Monitor memory usage:

  1. Check for common causes:

Slow Rendering Performance

Symptoms:

  • Server response times are slow

  • High CPU usage during rendering

Solutions:

  1. Profile your rendering:

  1. Optimize heavy operations:

Rendering Issues

Content Not Appearing

Symptoms:

  • Page renders but content is missing

  • "Loading..." or placeholder content shows

Solutions:

  1. Check async operations:

  1. Verify template syntax:

Hydration Mismatches

Symptoms:

  • Content flickers when client takes over

  • Console warnings about hydration mismatches

Solutions:

  1. Ensure consistent rendering:

  1. Use proper conditional rendering:

Debugging Techniques

Enable Debug Logging

Add detailed logging to understand the rendering process:

Use Node.js Debugger

  1. Start with debugging enabled:

  1. Open Chrome DevTools:

    • Navigate to chrome://inspect

    • Click "Open dedicated DevTools for Node"

Server-Side Console Output

Add strategic console.log statements:

Error Boundary Implementation

Create error boundaries to catch and handle SSR errors gracefully:

Configuration Issues

Webpack Bundle Problems

Symptoms:

  • "Module not found" errors in production

  • Different behavior between development and production

Solutions:

  1. Check externals configuration:

  1. Verify output configuration:

Middleware Configuration

Common middleware issues:

Deployment Issues

Production Environment Problems

  1. Environment variable configuration:

  1. Process management:

Docker Considerations

If using Docker, ensure proper Node.js and build setup:

Getting Help

If you're still experiencing issues:

  1. Check the browser console for client-side errors

  2. Review server logs for detailed error information

  3. Test with JavaScript disabled to verify SSR is working

  4. Compare with a minimal SSR setup to isolate the problem

  5. Search the Aurelia GitHub issues for similar problems

  6. Ask on the Aurelia Discord or forums for community help

Performance Monitoring

Set up monitoring to catch issues early:

Remember that SSR debugging can be complex due to the dual-environment nature. Always test both server-side rendering and client-side hydration to ensure your application works correctly in all scenarios.

Last updated

Was this helpful?