【问题标题】:Running the Angular compiler-cli (ngc); Cannot find module '@angular/core'运行 Angular 编译器-cli (ngc);找不到模块'@angular/core'
【发布时间】:2017-02-16 22:11:22
【问题描述】:

我尝试使用以下方法安装 Angular 编译器-cli (ngc):

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

安装似乎已经成功,但是现在当我运行ngc -p src 时,根据this question 的解决方案,我得到:

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 下运行良好。我在这里做错了什么?

【问题讨论】:

  • 如果你使用 Angular CLI,你不需要直接使用ngc。您应该使用 ng build --aot 进行 AoT 编译。请参阅此答案:stackoverflow.com/a/39167817/1377864 了解更多详情。

标签: angular typescript angular-cli


【解决方案1】:

如果您已经在使用 Angular CLI,只需使用 ng build 并让您担心正确调用 ngc

如果这是关于 AOT,那么请执行以下操作:

ng build -prod -aot

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

编辑: 我应该补充一点,您链接到的问题是针对 RC5,当时 Angular CLI 还是个婴儿。从那以后发生了很多变化,最好始终根据 Final 寻找答案。

【讨论】:

    猜你喜欢
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 2018-02-27
    • 2018-02-15
    • 2018-07-01
    • 2016-09-25
    相关资源
    最近更新 更多