kintela
kintela

Reputation: 1323

Source File Not Found in Angular CLI project

Hi I have this folders in my project Folders But When I run I get this error Error

Any idea please?

regards

Upvotes: 40

Views: 41973

Answers (13)

Ayesha
Ayesha

Reputation: 311

If your file is modal file, give extension to the file name. Do not keep it just with extension .ts ,for example empledo.modal.ts.

If your file is constants file, give extension to the file name as empledo.constants.ts.

Or you can keep file in asset folder if its dummy data and if it's not required.

Upvotes: 0

Yasasa Jayasuriya
Yasasa Jayasuriya

Reputation: 19

From my experience:

Just press ctrl with c (ctrl + c) to stop the compiler. Then re-run the command: ng serve

Upvotes: 1

Manjeet Suman
Manjeet Suman

Reputation: 95

This usually happens when you try to create a file using your IDE viz VS code etc. while your code is still compiling. You can stop the server using ctrl+c and then start then start it again using ng serve command to resolve the issue. Make sure that you saved all the files before running ng serve command .

Upvotes: 3

wins999
wins999

Reputation: 1492

Simplest Solution:

I also had the same issue,

The file was present in the directory but it was showing the above error.

Everything was proper but the error was not going.

then I closed the tab and again went to the directory through command prompt and again started the server:

ng serve --open

The error went !!!

Upvotes: 3

diana marcela Moreno
diana marcela Moreno

Reputation: 31

I have seen this error with the verifications of Angular 4 onwards.
You can solve this error like this.

  1. For the execution CTRL+C)
  2. Run or initialize the server (ng serve or npm start);

Upvotes: 3

Manoj Gupta
Manoj Gupta

Reputation: 474

When application is running state and at that if you add a file with some export class then it through this type error

ERROR in Source file not found: '/C/abc/xyz/pqr/apps/src/app/comm/ab.ts'.

Solution

restart application again then it works.

By using npm start command

Upvotes: 5

Chris Halcrow
Chris Halcrow

Reputation: 31950

Thanks to @Hisham Afzal Ahamed for the solution (stopping and re-starting the Angular compiler).

  • Stop the compiler: CTRL-C, CTRL-C (or CTRL-C then Y)
  • Restart: ng serve (or whatever else you're using e.g. a custom npm script)

Basically the Angular CLI sometimes doesn’t ‘see’ files that have been pulled in (e.g. when doing a merge while your compiler is running). Very useful to know. As a general time saver, If you’re pulling files into your solution or doing something similar, or you get an Angular compiler error that makes no sense, or you've made significant changes somehow, it’s always worth stopping then restarting the compiler to do a fresh build - it can save so many headaches!

Upvotes: 15

Rohit Gaidhane
Rohit Gaidhane

Reputation: 351

i also get this error

export class Product {

constructor(
  public productname: string,
  public qty: string,
  public price:string
) {  }

} this my product.ts file

solution:

the error is that i have written productname as product-name or product_name this both things are not allowed so i hope this will help you

Upvotes: 0

user10024820
user10024820

Reputation: 1

The error suggest that "source file not found".

This same error I was also getting. In my case by mistake I created a .ts file while ng server was running. The file was not needed so deleted it, from that point I stared getting the error.

I restore the file again without any code and the error is gone now.

Upvotes: 0

Hisham Ahamad
Hisham Ahamad

Reputation: 893

Rerunning ng serve should help fix the issue. You must have added empleado.ts while the local server was still running, hence Angular would not have seen the file.

Upvotes: 74

kintela
kintela

Reputation: 1323

After execute npm start again all works fine Thanks

Upvotes: 3

Ferus7
Ferus7

Reputation: 727

I guess empleado.ts is your class model for empleado, so you need to import in in your app.module

Upvotes: 0

Pardeep Jain
Pardeep Jain

Reputation: 86740

Try to put your empleado.ts file into assets folder and then fetch the file from there.

As, angular recommends to put all your resources in the assets folder including images/fonts/json etc and access from there.

PS: assuming this file contains your static content like dummy data etc.

Upvotes: 0

Related Questions