Npm run start-android-bundle throws "Module not found: Error: Can't resolve './app.module.ngfactory'"


#1

Just wanted to share something that happened to me and took away 5 hours of my life. Hopefully that will help someone else avoid the headache.

The Problem :crying_cat_face:

Trying to run npm run start-android-bundle fails with the following error:

ERROR in ./main.aot.ts
Module not found: Error: Can't resolve './app.module.ngfactory' in '/path/to/app'
 @ ./main.aot.ts 5:29-62

No other error, no nothing.

The Solution :smile_cat:

I’ve stumbled upon this thread: https://github.com/angular/angular-cli/issues/4551 on the angular-cli github repository. This stated a problem with the latest version of one of the dependencies of Angular’s AOT, named enhanced-resolve. Turns out it should be downgraded to version 3.3.0 for everything to work again.

So… to solve the problem, open package.json and add the next line inside devDependencies:
"enhanced-resolve": "3.3.0",

Voilà! :tada::tada::tada:

Hope it helps!
Shay.


#2

I feel your pain! It lost a few hours on that too.
You can check this issue in the nativescript-dev-webpack repo with some other poor souls that got burned.
Basically updating the @ngtools/webpack to 1.5.3 solved this for me.