错误找不到模块'./app.component.ngfactory'

我的错误如下:

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

我跑npm运行后生成app.module.ngfactory.ts是按预期创build的,但它创build了一个模块的引用,我没有/找不到:

从“./app.component.ngfactory”导入*作为import21;

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

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

我认为我的问题可能来自我跑步的事实

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

它想要一个名称分配给它正在创build的组件,我不知道这个名称可以是任何东西,或者如果它需要是特定的东西。 我已经尝试过名称NgFactory,app.component.ngfactory和我的项目的名称,但没有任何更改,我可以看到。 我也没有看到在我的tsconfig-aot.json文件中指定为genDir的文件夹,只有outDir。

在ngc完成之后,在aot文件夹(在tsconfig-aot.json中指定为genDir的文件夹)中查找NgFactory文件的集合。

以下是我的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 } 

}

请让我知道,如果你需要任何额外的信息。 我一直没能find任何东西,而且我一直在寻找两天。

我终于得到了app.component.ngfactory来build立/我的整个aot文件夹。 我更仔细地看了angular度食谱aot编译器,并决定重新做一些实例,下面是它的工作原理:

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 } }