The cli is attempting to use ahead of time compilation. Because of this, it needs to be able to find your main NgModule
.
Usually the AOT compiler is able to do this statically just by looking for bootstrap calls. However you are not immediately bootstrapping, so the compiler needs you to explicitly tell it the name of your app module so it can compile it and all of it's components.
Solutions
ng eject
and manually configure entryModule
The preferred solution is to tell the cli the name of your entryModule
. This will allow AOT to work and give you all of it's benefits. However the cli does not currently support this(But there is a PR for adding an option #4077).
The current workaround is to use ng eject --aot
to switch to a manual webpack based build. Then you can configure your entryModule
directly.
ng eject --aot
- Open
webpack.config.js
and search for new
AotPlugin
- Add the following and replace your
AppModule
name
entryModule: 'path/to/app.module#AppModule'
Skip AOT
You can entirely skip this issue by using the --no-aot
flag if you just need to get a build working. This isn't recommended as your app will be much slower and larger than it normally would(it will have to compile components at runtime and you will have to ship the compilier which is large).
ng prod --no-aot