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

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

问题描述

我尝试使用以下方法安装 Angular compiler-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天全站免登陆