angular-cli: --aot fails to build with no entryModule error
OS?
osX El Capitan
Versions.
angular-cli: 1.0.0-beta.18
node: 6.3.1
os: darwin x64
Repro steps.
When trying to use --aot
on an app without the standard app.module.ts pattern the build fails with the below error. As per the documentation tried adding the following to the tsconfig and that did not resolve the issue.
"angularCompilerOptions": {
"entryModule": "app/wfa-ng2.module#WfaNg2Module"
}
The log given by the failure.
Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
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 (/Users/zchapple/code/wfa-ts/node_modules/@ngtools/webpack/src/entry_resolver.js:143:15)
at AotPlugin._setupOptions (/Users/zchapple/code/wfa-ts/node_modules/@ngtools/webpack/src/plugin.js:105:77)
at new AotPlugin (/Users/zchapple/code/wfa-ts/node_modules/@ngtools/webpack/src/plugin.js:34:14)
at Object.exports.getWebpackAotConfigPartial (/Users/zchapple/code/wfa-ts/node_modules/angular-cli/models/webpack-build-typescript.js:57:13)
at new NgCliWebpackConfig (/Users/zchapple/code/wfa-ts/node_modules/angular-cli/models/webpack-config.js:18:42)
at Class.exports.default.Task.extend.run (/Users/zchapple/code/wfa-ts/node_modules/angular-cli/tasks/build-webpack.js:17:22)
at Class.Command.extend.run (/Users/zchapple/code/wfa-ts/node_modules/angular-cli/commands/build.js:50:26)
at Class.<anonymous> (/Users/zchapple/code/wfa-ts/node_modules/angular-cli/lib/models/command.js:152:17)
at tryCatch (/Users/zchapple/code/wfa-ts/node_modules/rsvp/dist/lib/rsvp/-internal.js:215:12)
at invokeCallback (/Users/zchapple/code/wfa-ts/node_modules/rsvp/dist/lib/rsvp/-internal.js:230:13)
at publish (/Users/zchapple/code/wfa-ts/node_modules/rsvp/dist/lib/rsvp/-internal.js:198:7)
at flush (/Users/zchapple/code/wfa-ts/node_modules/rsvp/dist/lib/rsvp/asap.js:85:5)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 27
- Comments: 41 (5 by maintainers)
Commits related to this issue
- feat(refoundry): publish a new package for refactoring. This package isnt public or stable yet, so no documentation. Also included fixes for: - Fixes #2887. — committed to hansl/angular-cli by hansl 8 years ago
- feat(refoundry): publish a new package for refactoring. This package isnt public or stable yet, so no documentation. Also included fixes for: - Fixes #2887. — committed to hansl/angular-cli by hansl 8 years ago
- feat(refoundry): publish a new package for refactoring. This package isnt public or stable yet, so no documentation. Also included fixes for: - Fixes #2887. — committed to hansl/angular-cli by hansl 8 years ago
- Workaround for issue that WebPack cannot find bootstrap See https://github.com/angular/angular-cli/issues/2887 — committed to arampp/pixapoint by deleted user 7 years ago
I have been facing the same issue when I have tried to load Module according to if statement.
This code could not compile with message:
To fix this error I have made another typescript file (just as @LukasBombach explained):
and now main.ts look like this:
I can compile without any problems now.
ng version
Also breaks a hybrid app (angular 1 and 2) using the upgradeAdapter to bootstrap:
upgradeAdapter.bootstrap(document.body, [‘app’]);
Apparently…
I get this same error. If I remove the catch handler it works.
My workaround for now:
I got this error wen I use polymer with angular cli . to use that I had to creat main-polymer.ts
and main.ts
and in angular-cli.json
I have to set ‘main’ : ‘main-polymer.ts’
How I’m gone workaround this problem
I had the same issue when I wanted either to wait for
deviceready
event triggered bycordova
or bootstrap theappModule
immediately if running in the web.Changing the
main.ts
to the following worked for meIt seems like there may only be a single call to
bootstrapModule
. Previously I’d the call tobootstrapModule
in both placesif
andelse
branch.I was in process of upgrading an app that previously used angular-cli@1.0.0-beta.16 and came across same exact error message, however, this happens when I try to run AoT version, i.e. with platformBrowser, not platformBrowserDynamic. This can be seen on brand new angular-cli created project:
I have not been working in direct Angular web app for several months, am I missing something?
I have a similar setup that leads to this error:
@criticalbh, nice workaround!
However, am I right to assume that
PreviewModule
extendsLandingModule
, hence all is fine for both usages even though Angular CLI will only have used the first as a starting point to determine what code to include in the generated bundles?If true, then I guess that specifying that module as the entry module in
tsconfig.json
would give you the same results, with the original code?(The above solves things for me, but requires the entry module to hit all code that other modules need. In our case,
ng build -prod --aot
actually only needs to support the module we defined inentryModule
, as the other code is just for our own use and deployed on a different server, for which we don’t require the speed improvements given by AOT.)i had this problem
when move files in webstorm, it refacted with extension and this is the problem. To solve change this:
import { AppModule } from 'app/app.module.ts';
to:
import { AppModule } from 'app/app.module';
Did some more debugging on this and found that the issue is around the parsing of the
main.ts
file. @clydin is right in that the CLI tries to resolve first. Which it does resolve my main.ts file correctly but because I have my bootstrap module wrapped in aDOMContentLoaded
block it cannot parse the bootstrapModule. Putting your bootstrap in this block breaks.Ok I just solved it. I cannot declare the
AppModule
within the same file as I dobootstrapModule
. I had to put all theAppModule
code in an own file and import it to themain.ts
.Just FYI: in the latest v1.0.0-beta.25 (and possibly earlier as well, but then the search was not recursive flag yet; #3708), the same error will show if more than 1 item is found.
In our case, we use conditional bootstrapping of multiple modules (a quite hacky way to implement widgets until a verdict is known for Angular angular/angular#13035), something like the nasty:
To show how many items were found, adjust @ngtools/webpack/src/entry_resolver:
Also note that output from that
console.info
line is only shown when restartingng serve
; when making changes to somemain.ts
without restartingng serve
then that logging is not shown. So I assumeangular-cli
then uses its cache (with possibly old bootstrap modules?). Just posting that here in case it helps someone.Ok, my fault!! app directory was in the .gitignore and this is the reason why the server fails doing
ng build
hehei used @juristr 's suggestion and it worked! Thanks,
I’m having same issue, it started when I enabled HMR feature in the Angular-cli and the BootstrapModule is not wrapped under any DOM element, my main.ts below:
any idea how to resolve this issue without revert back HRM?
@kevto rerun
npm install
work for me!.Recently I upgraded my angular-cli to the latest version to this date. I ran into the same error as OP while creating a migration-project. The project failed to install all the right dependencies and then I tried to start the server by angular-cli anyhow.
Resolution My fix was simply to
cd
into the new project folder,npm install
once again (which basically installed every dependency defined in package.json) andng build
, which did the trick.Update If you do happen to use Docker to build and serve your Angular2 application, you now have to specifically specify your container’s IP address while launching your application.
It would seem that the only the top-level of the
main.ts
file is searched for thebootstrapModule
call. By allowing it to search into nested calls(changefalse
totrue
) it picks it up properly, and works for me.Source: https://github.com/angular/angular-cli/blob/master/packages/webpack/src/entry_resolver.ts#L151.