[Fixed] Using realative paths in Angular: Cannot find module


I am trying to import a class from a different component in Angular. But I keep getting error the Error:

Cannot find module './app/_services/modal.service' or its corresponding type declarations.

My import statement looks like this

import {ModalService} from './app/_services/modal.service';

My directory tree looks like this, I am trying to go from the chatcomponent to _services:

  • src
    • /app
      • /_services
      • /chat-app
        • /chat/chatcomponent.ts


You should start the import path from src folder src/app/_services/modal.service or you should move back two folders so to reach _services folder ../../_services/modal.service

Leave a Reply

(*) Required, Your email will not be published