Skip to content
Back to Blog
Hosting Support10 min read

Troubleshooting Common Angle Errors: A Step-by-Step Guide

Diagnose and fix the most frequent Angle framework errors with clear symptoms, root causes, and exact solutions for each problem.

Written by Abdul AbrorTechnical Hosting Support Engineer
Troubleshooting Common Angle Errors: A Step-by-Step Guide
On this page

Hosting Angular applications presents unique challenges that differ from traditional server-side frameworks. When errors occur in production environments, they often manifest differently than in development, making diagnosis critical. This guide walks through the most common Angle-related errors you'll encounter when hosting Angular apps, with systematic troubleshooting steps for each.

Understanding Angular Hosting Context

Before diving into specific errors, it's important to understand that Angular applications are typically served as static files from web servers like Nginx, Apache, or through hosting platforms. The framework runs entirely in the browser, which means many errors relate to:

  • Incorrect web server configuration
  • Asset path resolution issues
  • Browser compatibility and caching
  • API endpoint connectivity
  • Build and deployment mismatches

When troubleshooting, always check browser developer console first—most Angular errors appear there rather than in server logs.

Error 1: 404 on Page Refresh (Angular Routing)

Symptoms

  • Application loads correctly on initial visit
  • Navigation works fine using in-app links
  • Direct URL access or page refresh returns 404 Not Found
  • Problem occurs only on routes other than the root path

Root Cause

Angular uses client-side routing by default with HTML5 pushState. When you refresh the page or access a deep link directly, the browser requests that path from the server. Without proper configuration, the web server looks for a physical file at that path and returns 404.

Fix for Nginx

Add a try_files directive to your Nginx configuration:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/angular-app/dist;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

This tells Nginx to serve index.html for any request that doesn't match a physical file, allowing Angular's router to handle the URL.

Fix for Apache

Create or modify .htaccess in your application root:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

Ensure the mod_rewrite module is enabled on your Apache server.

Fix for cPanel Shared Hosting

In cPanel environments, place the .htaccess file in the public_html directory (or subdirectory where your app is deployed). If using a subdirectory, adjust the RewriteBase accordingly:

RewriteBase /subdirectory/

Error 2: Blank White Screen After Deployment

Symptoms

  • Application builds successfully
  • Upload to server completes without errors
  • Browser shows blank white page
  • Browser console shows errors about failed resource loading
  • Network tab reveals 404 errors for JavaScript and CSS files

Root Cause

This typically occurs when the base href in index.html doesn't match the deployment path, or when files are uploaded to the wrong directory. Angular generates paths relative to the base href, so incorrect configuration breaks all asset references.

Diagnosis Steps

  1. Open browser developer tools (F12)
  2. Check Console tab for loading errors
  3. Check Network tab for 404 responses
  4. Note the paths being requested vs. actual file locations

Fix

Verify your build command includes the correct base href:

ng build --base-href=/

For subdirectory deployments:

ng build --base-href=/subdirectory/

Alternatively, ensure your angular.json has the correct base href in build options:

"build": {
  "options": {
    "baseHref": "/",
    "deployUrl": "/"
  }
}

After rebuilding, upload the contents of the dist/your-project-name folder to your web root, not the dist folder itself.

Error 3: CORS Errors When Calling APIs

Symptoms

  • API calls work in development with ng serve
  • Production deployment shows CORS errors in console
  • Error message: "Access to fetch at 'API_URL' from origin 'SITE_URL' has been blocked by CORS policy"
  • API requests fail with no response data

Root Cause

During development, Angular CLI's proxy configuration masks CORS issues. In production, browsers enforce same-origin policy. If your Angular app and API are on different domains (or different ports), the API server must explicitly allow cross-origin requests.

Fix: Server-Side Solution

The proper fix is configuring CORS headers on your API server. For Node.js/Express:

const cors = require('cors');

app.use(cors({
  origin: 'https://yourdomain.com',
  credentials: true
}));

For Apache (via .htaccess on API server):

Header set Access-Control-Allow-Origin "https://yourdomain.com"
Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"

For Nginx (on API server):

add_header Access-Control-Allow-Origin "https://yourdomain.com" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;

Alternative: Proxy Through Same Domain

If you control the web server hosting your Angular app, configure a reverse proxy to route API requests:

Nginx configuration:

location /api/ {
    proxy_pass https://api-server.com/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}

This allows your Angular app to call /api/endpoint on the same domain, which Nginx forwards to the actual API server.

Error 4: Failed to Compile or Build Errors

Symptoms

  • ng build command fails
  • TypeScript compilation errors
  • Module not found errors
  • Memory heap errors during build

Root Cause

Build failures typically stem from dependency issues, TypeScript configuration problems, or insufficient memory allocation during compilation.

Diagnosis and Fixes

For dependency issues:

rm -rf node_modules package-lock.json
npm cache clean --force
npm install

For TypeScript errors:

Review the specific error messages. Common issues include:

  • Strict mode violations: Adjust tsconfig.json or fix type definitions
  • Missing type declarations: Install @types/package-name
  • Version mismatches: Ensure Angular, TypeScript, and RxJS versions are compatible

For memory errors:

Increase Node.js memory limit:

export NODE_OPTIONS="--max_old_space_size=4096"
ng build --prod

Or add to your package.json scripts:

"build": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build"

Error 5: Environment Variables Not Working

Symptoms

  • API URLs or configuration work locally
  • Production deployment uses wrong endpoints
  • Environment-specific values not applied

Root Cause

Angular bakes environment variables into the build at compile time, not runtime. If you build locally and deploy, it uses your local environment configuration. Additionally, environment files must be properly configured in angular.json.

Fix

Ensure your environment.ts and environment.prod.ts files exist with correct values:

// environment.prod.ts
export const environment = {
  production: true,
  apiUrl: 'https://api.yourdomain.com'
};

Build with production configuration:

ng build --configuration=production

For CI/CD pipelines, build on the server where deployment occurs, not locally. Many hosting platforms offer build services that can use environment variables during the build process.

Error 6: Assets Not Loading After Deployment

Symptoms

  • Images show broken icon
  • Fonts not rendering correctly
  • Custom stylesheets missing
  • Files exist in the deployed folder but return 404

Root Cause

Angular processes assets during build, but incorrect paths in code or misconfigured angular.json assets array can break references. Additionally, web server MIME type configuration may block certain file types.

Fix

Verify assets are copied during build in angular.json:

"assets": [
  "src/favicon.ico",
  "src/assets",
  "src/robots.txt"
]

Reference assets correctly in components:

// Correct
backgroundImage: url('/assets/images/banner.jpg')

// Incorrect (breaks with baseHref changes)
backgroundImage: url('assets/images/banner.jpg')

For Apache, ensure MIME types are configured:

AddType image/webp .webp
AddType font/woff2 .woff2

Error 7: Caching Issues After Updates

Symptoms

  • Updates deployed successfully
  • Users still see old version of application
  • Forcing hard refresh (Ctrl+F5) shows new version
  • Mix of old and new assets loaded together causing errors

Root Cause

Browsers and CDNs aggressively cache static assets. Without proper cache busting, users continue to load old JavaScript and CSS files even after deploying new versions.

Fix

Angular automatically adds content hashes to filenames during production builds. Ensure you're using:

ng build --prod --output-hashing=all

Configure appropriate cache headers on your web server. For Nginx:

location / {
    try_files $uri $uri/ /index.html;
    add_header Cache-Control "no-cache";
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

This caches assets aggressively (since they have unique hashes) while forcing index.html to revalidate each time.

General Troubleshooting Checklist

When facing any Angular deployment issue:

  1. Check browser console for JavaScript errors and failed network requests
  2. Verify file paths in Network tab match actual file locations
  3. Confirm web server configuration for routing, MIME types, and CORS
  4. Test build locally by serving the dist folder with a simple HTTP server
  5. Review server logs for access denied, permission, or configuration errors
  6. Clear browser cache and test in incognito mode
  7. Compare working environment settings with problematic deployment
  8. Check file permissions on uploaded files (typically 644 for files, 755 for directories)

Conclusion

Most Angular hosting errors stem from web server configuration rather than the framework itself. The routing fallback configuration, proper base href settings, and CORS headers solve the majority of deployment issues. When troubleshooting, always start with browser developer tools to identify whether the problem is client-side (JavaScript errors, failed resource loading) or server-side (incorrect routing, permission issues). Build your application with production flags, verify asset paths, and test thoroughly before deploying to production. With these systematic approaches, you can diagnose and resolve Angular deployment errors quickly and confidently.

FAQ

Why does my Angular app work locally but not on the server?

Local development uses Angular CLI's dev server, which handles routing automatically and provides helpful error messages. Production requires explicit web server configuration for client-side routing. Additionally, production builds are optimized and minified differently than development builds.

Should I commit my dist folder to version control?

No. The dist folder contains build artifacts that should be regenerated for each deployment. Commit source code only, and build as part of your deployment process. This ensures environment-specific configurations are applied correctly.

How do I debug a completely blank page with no console errors?

This usually indicates the wrong files were uploaded. Verify you deployed the contents of dist/project-name, not the dist folder itself. Also check that index.html is in the web root directory your server is configured to serve from.

Can I deploy multiple Angular apps to the same domain?

Yes, using subdirectories. Build each app with the appropriate base href (/app1/, /app2/), deploy to matching directories, and configure your web server to route each path correctly with the try_files directive.

What's the difference between --prod and --configuration=production?

The --prod flag was deprecated in Angular version 12 and above. Use --configuration=production instead, which applies all production optimizations including AOT compilation, tree shaking, minification, and environment replacement.