main-aot is missing from the typeScript compilation

有些话、适合烂在心里 提交于 2019-12-13 17:24:47

问题


I am trying to implement ngc compilation config on my angular/webpack app. I have a tsConfig-aot.json in my root folder like below.

{
   ....
  "files": [
    "src/app/app.module.ts",
    "src/app/lazy/about/about.module.ts",
    "src/app/lazy/employees/employees.module.ts",
    "src/app/lazy/login/login.module.ts",
    "src/app/lazy/employee-details/employee-details.module.ts"
  ],
  "include": [
    "src/polyfills.ts",
    "src/vendor.ts"
  ],
  "exclude": [
    "./node_modules",
    "./**/*.e2e.ts",
    "./**/*.spec.ts",
    "./src/main-aot.ts"
  ],
  "angularCompilerOptions": {
    "genDir": "./aot",
    "skipMetadataEmit": true
  }
}

And my webpack is configured as below .

module.exports = {
    entry: {
        'polyfills': './src/polyfills.ts',
        'vendor': './src/vendor.ts',
        'app': './src/main-aot.ts'
    },

    resolve: {
        extensions: ['.ts', '.js']
    },

    module: {
        rules: [
            {
                test: /\.ts$/,
                loaders: [
                    {
                        loader: '@ngtools/webpack',
                        options: { configFileName: helpers.root('tsconfig-aot.json') }
                    }, 'angular-router-loader?aot=true&genDir=aot/', 'angular2-template-loader'
                ],
                exclude: [/node_modules/, /\.(spec|e2e)\.ts$/]
            },


        ]
    },

    plugins: [
        new AngularCompilerPlugin({
            tsConfigPath: 'tsconfig-aot.json',
            sourceMap: true
        }),

        new webpack.optimize.CommonsChunkPlugin({
            names: ['app', 'vendor', 'polyfills']
        }),
        ...
    ]
};

I am trying to implement the aot build config for my app. However, when i run ./node_modules/.bin/ngc -p ./tsconfig-aot.json. My app compilation fails with the error saying

src/main-aot is missing from the TypeScript compilation

My main.aot is written as below

import { platformBrowser } from '@angular/platform-browser';
import { enableProdMode } from '@angular/core';

import { AppModuleNgFactory } from '../aot/src/app/app.module.ngfactory';
enableProdMode();

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);

When i update my tsconfig-aot to by adding main-aot in files object, the error changed to "aot/src/app/app.module.ngfactory" has no exported member 'AppModuleNgFactory'. I presumed the later is because the aot folder has not been generated yet. Please how do i properly configure this ? Any help would be appreciated.

来源:https://stackoverflow.com/questions/48862003/main-aot-is-missing-from-the-typescript-compilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!