Vern Jensen
Vern Jensen

Reputation: 3560

Angular-CLI build: ERROR in Cannot read property 'getSourceFile' of undefined

I'm attempting to get Angular CLI working for an existing (fairly large) Angular 2 project. I started by following the CLI Quickstart, and got the Hello World project running.

After that I've been trying to copy my existing project into the CLI project and get it building. After fixing a lot of errors, I'm left with just one when I execute the "ng serve" or "ng build" commands:

Cannot read property 'getSourceFile' of undefined

I found this GitHub thread that suggested replacing WebPack's _resolve() function in

node_modules@ngtools\webpack\src\compiler_host.js

I replaced that in both my local NPM's Angular-CLI AND in the global one: [user]\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\compiler_host.js

I still get the error.

I notice that the version of WebPack here is 1.3.0, whereas the current one available in NPM is 1.4.1. It also says that my globally installed Angular CLI is "1.0.0" whereas the latest in NPM shows up as 1.0.0-beta-28.3

Can anyone explain if 1.0.0 is the latest, or 1.0.0-beta-28.3? Why does 1.0.0 not show up in NPM at all, but it seems to be installed on my computer?

And most importantly, any ideas how to resolve this error?

Upvotes: 0

Views: 4919

Answers (6)

Muhammad Qasim
Muhammad Qasim

Reputation: 107

I resolved this problem by removing deleted component's reference from my module that yet was accidentally there.

Upvotes: 0

Raj
Raj

Reputation: 249

I was getting the same error.

I resolved the issue just by closing the existing Angular-CLI command prompt and re-ran the ng serve in a new command prompt.

Upvotes: 4

ppenchev
ppenchev

Reputation: 157

I was getting the same error and spent around 1 hour of wondering what is going on. Finally I just stopped it and run it again like that - Ctrl + F5 and npm start and it worked as it was never been broken... What I'm noticing so far in Angular 4 is that many problems could be resolved with stop(Ctrl + F5)/ start(npm start) or rebuild packages with npm rebuild or delete all node_modules and install them again with npm install If none of those suggestions work you can start digging in google :)

Upvotes: 0

user3444999
user3444999

Reputation: 571

I was getting the same error, when I started ng-serve and I didnt waited for webpack to compile and ran http://localhost:4200/# One reason I can think was the webpack didnt compiled all those modules and before it self I started those components by hitting index.html and thats why it failed.

But when I restarted with ng-serve , I waited for webpack: Compiled successfully. message on terminal and then went to http://localhost:4200/# It worked well. hope that helps.

Upvotes: 1

Tubasa
Tubasa

Reputation: 11

I re-installed angular/cli from the cmd and the error is resolved.

Note: Like that: npm install -g @angular/cli

Upvotes: 1

Vern Jensen
Vern Jensen

Reputation: 3560

I ended up solving this by updating TypeScript in npm to 2.3.x. I believe formerly I was on 2.0.x, and Angular is now using 2.1.x and wants that version or newer.

There was then an additional (and similarly cryptic) error that I resolved by ensuring that the version of Angular installed matched the version of the CLI compiler. (I was on Angular 2.x and needed to upgrade to 4.x)

Upvotes: 0

Related Questions