0

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?

3
  • 1.0.0 is surely the latest. It uses Webpack 2+. Commented Apr 18, 2017 at 0:38
  • Thanks Tatsuyuki. Any idea why 1.0.0 doesn't show up when doing "npm view angular-cli version"? Also, any idea why it seems to be using Webpack 1.3.0 instead of 1.4.1? How would I update my "globally installed" Angular-CLI to use a newer version of Webpack? Commented Apr 18, 2017 at 0:40
  • the angular-cli has been renamed @angular/cli, you should try install it by npm install -g @angular/cli@latest, and see its version info by npm view @angular/cli version or ng -v. Commented Apr 18, 2017 at 1:09

6 Answers 6

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

1

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.

Comments

0

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)

Comments

0

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 :)

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.