【问题标题】:Error in [at-loader] Cannot find module './app.component.ngfactory'[at-loader] 中的错误找不到模块“./app.component.ngfactory”
【发布时间】:2017-05-08 14:38:47
【问题描述】:

我的错误如下:

[at-loader] assets\app\app.module.ngfactory.ts:28:27 中的错误 找不到模块“./app.component.ngfactory”。

在我运行 npm run build 后,app.module.ngfactory.ts 已按预期创建,但它创建了对我没有/找不到的模块的引用:

import * as import21 from './app.component.ngfactory';

查看aot-complier 链接,我在编译应用程序部分看到以下内容:

好奇的可以打开aot/app.component.ngfactory.ts查看 中间的原始 Angular 模板语法, 编译成 TypeScript 的形式。

我认为我的问题可能来自于我在运行时

“node_modules/.bin/ngc”-p tsconfig-aot.json

它希望为它正在创建的组件分配一个名称,我不确定该名称是否可以是任何名称,或者它是否需要特定的名称。 我尝试了 NgFactory、app.component.ngfactory 和我的项目名称,但这些都没有做出任何我可以看到的更改。我也没有看到在我的 tsconfig-aot.json 文件中指定为 genDir 的文件夹,只有 outDir。

ngc 完成后,在 aot 文件夹(在 tsconfig-aot.json 中指定为 genDir 的文件夹)。

以下是我的 tsconfig-aot.json 当前包含的内容:

    {
    "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "./public/js/app"
    },
    "exclude": [
    "node_modules",
    "dist",
    "assets/app/polyfills.ts"
    ],

    "angularCompilerOptions": {
    "skipMetadataEmit" : true
    }

}

如果您需要任何其他信息,请告诉我。我还没有找到任何关于这个的东西,我已经找了两天了。

【问题讨论】:

    标签: angularjs node.js angular2-aot


    【解决方案1】:

    我终于得到了 app.component.ngfactory 来构建/我的整个 aot 文件夹。我更仔细地查看了 angular cookbook aot-compiler 并决定重新进行一些实例化,以下是使其工作的原因:

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

    我猜它要么是第一次没有正确安装,要么发生了其他事情。安装后,我可以运行以下命令并生成 aot 文件夹:

    "node_modules/.bin/ngc" -p tsconfig.aot.json
    

    我还将 tsconfig.aot.json 文件更改为以下内容:

    {
      "compilerOptions": {
        "target": "es5",
        "module": "es2015",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "outDir": "./public/js/app"
      },
    
      "files": [
        "app/app.module.ts",
        "app/main.aot.ts"
      ],
    
      "exclude": [
        "node_modules",
        "dist",
        "assets/app/polyfills.ts"
      ],
    
      "angularCompilerOptions": {
        "genDir": "aot",
        "skipMetadataEmit" : true
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-06
      • 2020-12-09
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2020-02-02
      • 2023-02-20
      • 2020-01-29
      • 2018-06-04
      相关资源
      最近更新 更多