我想为我的应用程序设置AOT编译器。
当我运行node_modules/.bin/ngc -p tsconfig-aot.json时,它会成功编译,不会出现错误。
但是,当我尝试运行ng serve时,它会给出以下错误:
试图找到引导代码,但是找不到。指定静态可分析引导代码或将entryModule传递给插件选项.
Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
at Object.resolveEntryModuleFromMain (/path/node_modules/@ngtools/webpack/src/entry_resolver.js:128:11)
at AotPlugin._setupOptions (/path/node_modules/@ngtools/webpack/src/plugin.js:143:50)
at new AotPlugin (/path/node_modules/@ngtools/webpack/src/plugin.js:26:14)
at _createAotPlugin (/path/node_modules/@angular/cli/models/webpack-configs/typescript.js:55:12)
at Object.exports.getNonAotConfig (/path/node_modules/@angular/cli/models/webpack-configs/typescript.js:70:19)
at NgCliWebpackConfig.buildConfig (/path/node_modules/@angular/cli/models/webpack-config.js:27:37)
at Class.run (/path/node_modules/@angular/cli/tasks/serve.js:38:98)
at check_port_1.checkPort.then.port (/path/node_modules/@angular/cli/commands/serve.js:110:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)main.ts
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/src/app/main/app.module.ngfactory';
console.log('Running AOT compiled');
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);发布于 2017-08-21 09:12:26
node_modules/.bin/ngc -p tsconfig-aot.json将所有文件编译到输出文件夹中。您可以使用任何http服务器从该文件夹运行文件。
然而,在使用angular-cli进行开发时,通常不是这样做的。ng serve使用它自己的不关心output文件夹的开发服务器。如官方文件所述
ng serve构建应用程序并启动web服务器。 ..。以下是其他选项。 - aot
因此,您需要使用--aot选项:
ng serve --aot而且您不需要修改main.ts文件。它应该有boostrapModule,而不是boostrapModuleFactory方法。
https://stackoverflow.com/questions/45792911
复制相似问题