App.module.ngfactory missing after prod build in 2.0.0

Since updating to the latest version of ionic 2.0.0 and ionic-app-scripts our prod builds seem to have stopped working. ionic build android/ionic build ios work as expected but if we use --prod or --aot we get a blank screen with Error: Cannot find module "./app.module.ngfactory" in the inspector console.

We’ve done some reading around and found that a common cause of this issue is TypeScript version issues but we’ve checked and we are definitely using typescript 2.0.9. No errors are produced when running the prod build so we’re stuck for what the problem might be and the only major thing that has changed was the update to 2.0.0 and ionic-app-scripts 1.0.0. Possible there is some sort of error in ngc that is getting swallowed by app-scripts that we can’t see to fix?

1 Like

Just as an update, I tried downgrading to various versions of ionic-app-scripts and managed to get success when I hit 0.0.46 (re-instated and So the bug appears to be in 0.0.46 with the switch to virtual file system and the other breaking changes.

I’ve double checked the breaking changes to ensure that I didn’t miss any migrations - everything should be working. For whatever reason after 0.0.47 it can’t find the module.ngfactory when it runs the webpack step. I guess for now we’ll just keep using 0.0.46 until an update comes up.

After further digging, I’ve seen that the app.module.ngfactory is definitely getting written to the virtual file system, but for whatever reason webpack isn’t finding it when it processes main.ts. No idea why.


So I finally resolved this after many headaches and ripping pieces out of our app until I had it essentially back to the base ionic app…

Turns out it was a breaking change in 2.1+ which meant that custom webpack configs don’t work the way they did in <= 2.0.9.

I had a custom webpack config as follows:

const DefinePlugin = require('webpack/lib/DefinePlugin');

module.exports = {
  plugins: [
    new DefinePlugin({
      'process.env': {
        'NODE_ENV' : JSON.stringify(process.env.NODE_ENV || 'development')

In 2.0.9 this would work in conjunction with the usual prod build but in 2.1+ it seems to overwrite the default ionic webpack config completely resulting in my weird issue. I copied the full ionic webpack config from node_modules/@ionic/app-scripts/config to my ./config folder and added the DefinePlugin to that - and :tada: aot working again in the latest ionic-app-scripts.