Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running the Angular compiler-cli (ngc); Cannot find module '@angular/core'

Tags:

I've tried installing the Angular compiler-cli (ngc) using:

npm install @angular/compiler-cli typescript @angular/platform-server @angular/compiler

And the install appears to have worked, but now when I run ngc -p src, per the solution to this question, I get:

module.js:442
    throw err;
    ^

Error: Cannot find module '@angular/core'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at /usr/local/lib/node_modules/@angular/compiler/bundles/compiler.umd.js:7:83
    at Object.<anonymous> (/usr/local/lib/node_modules/@angular/compiler/bundles/compiler.umd.js:10:2)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)

My project runs fine with ng serve. What am I doing wrong here?

like image 742
BBaysinger Avatar asked Dec 31 '16 03:12

BBaysinger


1 Answers

If you're using Angular CLI already, just use ng build and let that worry about calling ngc correctly.

If this is about AOT, then do this:

ng build -prod -aot

and your /dist/ folder will contain what you need.

Edit: I should add that the question you linked to is for RC5, when Angular CLI was still an infant. There were so many changes since, it's best to always look for answers based on Final.

like image 125
Cobus Kruger Avatar answered Sep 23 '22 10:09

Cobus Kruger