Alon Alon - 2 years ago 59
Javascript Question

Getting 'Module not found' although file exists

I downloaded the angular starter and ran the app and it ran well. Now I Added a new file "people.service.ts" located in "src/app/services/people.service.ts".

When I try to import it, I get an error:

Module not found: Error: Can't resolve 'services/people.service' in

This is the code I use to import it (in src/app/app.module.ts):

import {PeopleService} from 'services/people.service';

I'm sure that there's no typos because the IDE recognizes it. There isn't any TypeScript error in the entire project. The file 'services/people.service' does contain a class named PeopleService.

Any help will be profoundly appreciated. Please let me know if you need any additional information.

Answer Source

The problem is that you're using absolute path instead of a relative path. Change the import to the following:

import {PeopleService} from './services/people.service';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download