运行Angular编译器cli(ngc);找不到模块'@ angular/core' [英] Running the Angular compiler-cli (ngc); Cannot find module '@angular/core'

查看:115
本文介绍了运行Angular编译器cli(ngc);找不到模块'@ angular/core'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下命令安装Angular编译器cli(ngc):

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

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

安装似乎已经成功,但是现在当我运行ngc -p src时,按照

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)

我的项目在ng serve下运行良好.我在这里做什么错了?

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

推荐答案

如果您已经在使用Angular CLI,则只需使用ng build,然后就不必担心正确调用ngc了.

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

如果这与AOT有关,请执行以下操作:

If this is about AOT, then do this:

ng build -prod -aot

和您的/dist/文件夹将包含您需要的内容.

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

我还要补充一点,当Angular CLI还是婴儿时,您链接到的问题是针对RC5的.此后发生了太多变化,最好总是根据Final来寻找答案.

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.

这篇关于运行Angular编译器cli(ngc);找不到模块'@ angular/core'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆