angular: AOT: ngfactory files no longer being generated

I’m submitting a…


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When running ngc -p tsconfig-aot.json I get

app/main-aot.ts(3,34): error TS2307: Cannot find module ‘…/compiled/app/app.module.ngfactory’.

It worked perfectly fine with Angular 4.x, I changed the tsconfig-aot.json accordingly.

Expected behavior

Compilation should work flawlessly.

Environment


Angular version: 5.0.0
 
For Tooling issues:
- Node version: 8.4.0  
- Platform:  Windows 10
- TypeScript: 2.4.2

tsconfig-aot.json

{
    "compilerOptions": {
        "target": "es2015",
        "module": "esnext",
        "moduleResolution": "node",
        "sourceMap": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true,
        "rootDir": ".",
        "baseUrl": "./app",
        "lib": [
            "dom",
            "es5",
            "es2015",
            "es2016",
            "es2017.object"
        ],
        "outDir": "compiled"
    },
    "files": [
        "app/app.module.ts",
        "app/main-aot.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts",
        "app/testing",
        "tslint",
        "config"
    ],
    "angularCompilerOptions": {
        "annotationsAs": "decorators",
        "entryModule": "app/app.module#AppModule",
        "skipMetadataEmit": true,
        "preserveWhitespaces": false
    }
}

main-aot.ts:

import {platformBrowser} from "@angular/platform-browser";

import {AppModuleNgFactory} from "../compiled/app/app.module.ngfactory";

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 20 (4 by maintainers)

Most upvoted comments

Could you please provide a minimal reproduction of your issue, the code you have supplied is not enough to reproduce your issue. Also have you followed our upgrade guide? https://angular-update-guide.firebaseapp.com/

Okay, fixed (at least for me):

You need to be absolutely sure to use a path in your main-aot.ts file that is pointing to the same app.module file, but with the “.ngfactory” suffix, e.g. for me, my main-aot.ts is lying in the same folder as my app.module.ts:

import { AppModuleNgFactory } from “./app.module.ngfactory”;

yes,i found it, thanks so much! it was hell this Angular 5 migration.

@p3x-robot in @ngtools/webpack, there are now 2 plugins. AngularCompilerPlugin, which is for Angular v5+ and AotPlugin, which is for v4 and older. Please use the correct one.