Introduction

Angular fails to resolve module imports when the path is incorrect, the module doesn't exist, or TypeScript path mapping is misconfigured. This results in build failures or runtime errors.

Symptoms

Module not found:

```bash $ ng build

Error: src/app/app.module.ts:3:26 - error TS2307: Cannot find module './shared/shared.module' or its corresponding type declarations. ```

Import resolution error:

bash
Error: Module '"./app.component"' has no exported member 'AppComponent'.

Path alias error:

bash
Error: Cannot find module '@shared/components' or its corresponding type declarations.

Common Causes

  1. 1.Wrong import path - Typo or incorrect relative path
  2. 2.Missing file - File deleted or not created
  3. 3.Wrong file extension - Importing with .ts extension
  4. 4.Barrel export missing - index.ts not exporting module
  5. 5.tsconfig paths wrong - Path alias not configured
  6. 6.Case sensitivity - Different case in import vs filename
  7. 7.Module not exported - Module exists but not exported from barrel

Step-by-Step Fix

  1. 1.Identify the error in logs
  2. 2.Verify configuration settings
  3. 3.Test connectivity
  4. 4.Apply corrective action
  5. 5.Verify the fix

Step 1: Verify File Exists

```bash # Check if the file exists ls -la src/app/shared/shared.module.ts

# Or on Windows: dir src\app\shared\shared.module.ts

# List all files in directory ls src/app/shared/

# Search for the file find . -name "shared.module.ts" 2>/dev/null

# If file doesn't exist, create it or fix import path ```

Step 2: Check Import Path

```typescript // WRONG: Incorrect relative path import { SharedModule } from './shared/shared.module'; // From app.module.ts

// If app.module.ts is in src/app/ and shared is in src/app/shared/ // This is CORRECT

// WRONG: Missing directory level import { SharedModule } from './shared.module'; // Wrong - missing shared/

// CORRECT: Full relative path import { SharedModule } from './shared/shared.module';

// WRONG: With file extension import { SharedModule } from './shared/shared.module.ts'; // Don't include .ts

// CORRECT: Without extension import { SharedModule } from './shared/shared.module'; ```

Step 3: Check Barrel Exports

```typescript // Check if shared/shared.module.ts exists and exports correctly // src/app/shared/shared.module.ts @NgModule({ declarations: [SharedComponent], exports: [SharedComponent] // Must export to be accessible }) export class SharedModule { }

// Check barrel file (index.ts) // src/app/shared/index.ts export * from './shared.module'; export * from './shared.component';

// Now you can import from barrel import { SharedModule } from './shared'; // Uses index.ts

// Without barrel, you need full path import { SharedModule } from './shared/shared.module'; ```

Step 4: Configure TypeScript Paths

```typescript // In tsconfig.json, configure path aliases { "compilerOptions": { "baseUrl": "./", "paths": { "@app/*": ["src/app/*"], "@shared/*": ["src/app/shared/*"], "@components/*": ["src/app/components/*"], "@services/*": ["src/app/services/*"] } } }

// Now you can use aliases import { SharedModule } from '@shared/shared.module'; import { UserService } from '@services/user.service';

// Check tsconfig.json exists and paths are correct cat tsconfig.json | grep -A 10 "paths" ```

Step 5: Check Case Sensitivity

```bash # Linux is case-sensitive, Windows is not # This can cause issues when deploying to production

# Check actual filename ls src/app/shared/ | grep -i shared

# If file is SharedModule.ts but import is shared.module: # - Works on Windows (case-insensitive) # - Fails on Linux (case-sensitive)

# FIX: Match case exactly // If file is SharedModule.ts import { SharedModule } from './shared/SharedModule'; // Match case ```

Step 6: Check Module Exports

```typescript // src/app/shared/shared.module.ts @NgModule({ imports: [CommonModule], declarations: [ SharedComponent, AnotherComponent ], exports: [ SharedComponent, // Must export to use in other modules AnotherComponent ] }) export class SharedModule { }

// If you forgot to export: // ERROR: 'SharedComponent' is not exported by 'SharedModule'

// FIX: Add to exports array exports: [SharedComponent, AnotherComponent] ```

Step 7: Check node_modules Imports

```typescript // For external modules, verify package is installed import { SomeModule } from 'some-library';

// Check if package exists npm list some-library

// If not installed: npm install some-library

// Check package.json cat package.json | grep some-library

// Check if module has exports ls node_modules/some-library/ cat node_modules/some-library/package.json | grep "main|exports" ```

Step 8: Clear Angular Cache

```bash # Clear Angular CLI cache rm -rf .angular/cache

# Or via ng command ng cache clean

# Clear node_modules and reinstall rm -rf node_modules rm package-lock.json npm install

# Rebuild ng build ```

Step 9: Check Angular.json Configuration

```bash # Check project structure in angular.json cat angular.json | grep -A 5 "sourceRoot"

# Verify sourceRoot points to correct directory # "sourceRoot": "src"

# Check if file is included in project # Files outside sourceRoot won't be resolved ```

Step 10: Debug with Verbose Output

```bash # Run build with verbose output ng build --verbose

# Check TypeScript tracing ng build --verbose 2>&1 | grep -i "module"

# Enable TypeScript tracing // In tsconfig.json: { "compilerOptions": { "traceResolution": true } }

// Run build and check trace ng build 2>&1 | grep -A 5 "Resolving module" ```

Common Import Path Patterns

Import StyleWhen to UseExample
RelativeSame module or nearby./shared/shared.module
Parent relativeParent directories../shared/shared.module
Path aliasCross-module imports@shared/shared.module
node_modulesExternal packages@angular/common

Verification

```bash # After fixing import path # Run build ng build

# Should succeed without module errors

# Check for any remaining errors ng build 2>&1 | grep -i "cannot find"

# Run tests ng test

# Verify in development ng serve

# Should compile without errors ```

Prevention

To prevent Angular module not found issues from recurring, implement these proactive measures:

1. Use Path Aliases Consistently

```json // tsconfig.json { "compilerOptions": { "baseUrl": ".", "paths": { "@core/*": ["src/app/core/*"], "@shared/*": ["src/app/shared/*"], "@features/*": ["src/app/features/*"] } } }

// Use in imports import { SharedModule } from '@shared/shared.module'; import { CoreModule } from '@core/core.module'; ```

2. Validate Imports in CI/CD

yaml
# .github/workflows/ci.yml
- name: Check Imports
  run: |
    ng build --configuration production
    # Build fails if imports are invalid

3. Use Angular Schematic for Modules

```bash # Generate module with correct paths ng generate module features/user --module app --route user

# This ensures: # - Correct import path # - Proper routing setup # - Module registration ```

Best Practices Checklist

  • [ ] Use path aliases for imports
  • [ ] Validate imports in CI/CD
  • [ ] Use Angular CLI for module generation
  • [ ] Document module structure
  • [ ] Use strict TypeScript settings
  • [ ] Review import paths in code review
  • [Fix Angular Dependency Injection Error](/articles/fix-angular-dependency-injection-error)
  • [Fix Angular Ivy Compilation Failed](/articles/fix-angular-ivy-compilation-failed)
  • [Fix TypeScript Cannot Find Module](/articles/fix-typescript-cannot-find-module)
  • [Technical troubleshooting: Fix Browser Back Button State Lost Spa Navigation ](browser-back-button-state-lost-spa-navigation)
  • [Fix Cors Fetch Localhost Development Blocked Issue in Frontend](cors-fetch-localhost-development-blocked)
  • [Fix Csp Violation Blocked Inline Script Style Issue in Frontend](csp-violation-blocked-inline-script-style)
  • [Fix Angular Change Detection Loop](fix-angular-change-detection-loop)
  • [Fix Angular Dependency Injection Error](fix-angular-dependency-injection-error)

<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Angular Module Not Found", "description": "Troubleshoot Angular module not found errors. Check import paths, barrel exports, and TypeScript configuration.", "url": "https://www.fixwikihub.com/fix-angular-module-not-found", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-04T03:20:29.663Z", "dateModified": "2026-04-04T03:20:29.663Z" } </script>