2

I had a working project including a service that was stored in a file called demo.service.ts. In the same file I had two classes that was my model, like so.

@Injectable({ providedIn: "root" })
export class DemoService { ... }
export class Donkey { ... }
export class Monkey { ... }

Each file that used that service and model imported all three classes like this.

import { DemoService, Donkey, Monkey } from "../demo.service";

Then I decided to refactor to keep the model classes in a separate file called demo.model.ts. Of course, I had to alter the import statement as follows.

import { DemoService, Donkey, Monkey } from "../demo.service";
import { Donkey, Monkey } from "../demo.model";

The errors reported in the console got less and less as I've kept updating. However, now that all the imports are altered, I still get the error message below.

ERROR in Source file not found: '/C/.../src/app/demo/demo.model.ts'.

I have no idea what is trying to get to the file nor why it can't find it. Googling produces a lot of errors from sites unrelated to Angular or blogs like this that seem to work after doing the equivalent of my attempt.

I tried to remove or change the imports in each of the files using them and got immediately more error messages. Hence, I concluded that those are pointing to the correct locations.

What more can I dig up to trouble-shoot this problem?

Flip
  • 6,233
  • 7
  • 46
  • 75
DonkeyBanana
  • 3,266
  • 4
  • 26
  • 65
  • Does this answer your question? [Source File Not Found in Angular CLI project](https://stackoverflow.com/questions/50233046/source-file-not-found-in-angular-cli-project) – mao95 Jul 12 '20 at 10:34

2 Answers2

1

i had the same issue and finally fixed it with omitting the component class (DemoComponent in your case) from declarations array in app.module.ts .

Far
  • 420
  • 5
  • 14
0

Noticed this error while building with Ionic. So I exited live reload (Ctrl + C on command prompt) and recompiled the app (ionic serve or in your case, ng serve).

Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72