[at-loader] 中的错误找不到模块'./app.component.ngfactory'

Error in [at-loader] Cannot find module './app.component.ngfactory'

我的错误如下:

[加载程序] 中的错误 assets\app\app。module.ngfactory.ts:28:27 找不到模块 './app.component.ngfactory'.

在我 运行 npm 运行 构建应用程序之后。module.ngfactory.ts 已按预期创建,但它创建了对我不 have/can 的模块的引用找到:

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

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

The curious can open the aot/app.component.ngfactory.ts to see the original Angular template syntax in its intermediate, compiled-to-TypeScript form.

我认为我的问题可能是因为当我 运行

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

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

After ngc completes, look for a collection of NgFactory files in the aot folder (the folder specified as genDir in 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"
    },
    "exclude": [
    "node_modules",
    "dist",
    "assets/app/polyfills.ts"
    ],

    "angularCompilerOptions": {
    "skipMetadataEmit" : true
    }

}

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

我终于得到了 app.component.ngfactory 到 build/my 整个 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
  }
}