Angular4 min read2026-03-01
Angular Cannot Find Module
Fix error TS2307: Cannot find module '...' or its corresponding type declarations in Angular.
Error Code / Stack Trace
error TS2307: Cannot find module './user.service' or its corresponding type declarations.Problem Overview
The Angular TypeScript compiler (ng build or ng serve) cannot locate the referenced service, component, or external npm module.
Why Does This Happen?
- File path typo or incorrect relative import (e.g. missing ../ traversal).
- Missing .ts extension or file renamed without updating imports.
- The npm package is not installed or missing from package.json.
Step-by-Step Solution
Step 1: Check relative file path and casing
Verify that the service or component path matches the directory layout exactly.
typescript
// Check relative directory:
import { UserService } from '../services/user.service';Step 2: Install missing package
If importing from a library, ensure it is installed in node_modules.
bash
npm install @angular/forms --saveCommon Mistakes to Avoid
- •Importing a component file before declaring it in a module or declaring standalone: true.
Prevention & Best Practices
- Use modern Angular Standalone Components (Angular 14+) to simplify imports.
Frequently Asked Questions
Should I include .ts in import statements in Angular?
No, TypeScript expects extensionless imports for .ts and .tsx files.
Related Developer Solutions & Tools
Recommended Tools
Related Error Fixes