ionic-framework: app.module.ngfactory failing PRD build

Short description of the problem:

Getting the following:

[13:28:27]  Error: Could not resolve entry (.tmp/app/main.prod.js)
    at /home/xx/dev/xx/xx/xxx-ionic/node_modules/rollup/dist/rollup.js:8602:28
    at process._tickCallback (internal/process/next_tick.js:103:7)

The AppModuleNgFactory cannot be resolved:

import {AppModuleNgFactory} from "./app.module.ngfactory";

So main.prd.ts doesn’t compile and the whole build fails.

I’ve searched all over and couldn’t find an appropriate fix for this issue.

What behavior are you expecting?

I can build the project and run it on android

Steps to reproduce:

  1. ionic run android
insert any relevant code between the above and below backticks

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

Which Ionic Version? 1.x or 2.x v2 RC.0

Run ionic info from terminal/cmd prompt: (paste output below) Cordova CLI: 6.2.0 Ionic Framework Version: 2.0.0-rc.0 Ionic CLI Version: 2.1.0 Ionic App Lib Version: 2.1.0-beta.1 OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Node Version: v6.7.0

npm -v 3.10.8 node -v v6.7.0

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 63 (18 by maintainers)

Most upvoted comments

We just got this on our TeamCity build agents, but not on local machines. After quite a bit of debugging, it turned out the build agents had a newer version of TypeScript. Locking our version of TypeScript to version 2.0.9 solved the problem for us (both Android and iOS builds).

TLDR: npm install typescript@2.0.9 --save-dev

@vegardlarsen Thanks. Solved My issue.

It appears there are a couple of different issues that are similar, so things to check:

  • There’s an src/app/main.prod.ts file
  • @angular/compiler-cli has been installed
  • The app can be compiled with the Ahead of Time compiler (maybe error reporting isn’t working)

The Angular’s Ahead of time (AoT) compiler is very strict and what passes for dev mode probably isn’t passing for production mode. ionic serve is only in dev mode, but the build is production. We’ll get the error reporting improved for this.

thanks @vegardlarsen you saved my night 👍

@jorgedkoala Thanks! I solve change: import { TranslateModule, TranslateLoader,TranslateStaticLoader } from 'ng2-translate/ng2-translate'; to import { TranslateModule, TranslateLoader } from 'ng2-translate/ng2-translate'; import { TranslateStaticLoader } from 'ng2-translate';

I have the same problem: I receive the "Cannot find module ‘./app.module.ngfactory’. " error when I run ionic build, but not when running the serve. I have updated the scripts, node, npm, etc. as recommended here. I have removed the node_modules, .tmp and www directories multiple times before rebuilding.

I am able to build the tutorial app. I believe the problem is in an external .js based node_module that I added, probably either ng2-charts or angular2-select. The biggest problem is that there is no real error message provided, so I don’t know how to fix it. I have read elsewhere that the problem might be that a .manifest.json file needs to exist in the third party module. If so, what would that need to look like?

@adirzoari,

Can you install the latest version of @ionic/app-scripts?

npm install @ionic/app-scripts@latest

+1

@danbucholtz Can you reopen this issue?

@FanYeeChok As stated by @danbucholtz, the ngfactory is part of the ngc compilation and it’s normal that it’s missing from the src/app directory.

Hello SOLVED in my case, after updated the app-scripts i could find the error [10:12:41] ngc error: Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 37:23 in the original .ts file), resolving symbol AppModule in /Users/koala/Documents/angular/tfc-mobile/.tmp/app/app.module.ts

Produced by how i was calling “My Fault” the TranslateStaticLoader of ng2-translate service. Now (AoT) is compiling a running. Thanks a lot for your help.

Double checked

  • That is src/app/main.prod.ts
  • That is node_modules/@angular/compiler-cli

Still hitting the same error while ionic build ios

[10:17:52]  ngc error: Compilation failed
[10:17:52]  ngc failed:  NGC encountered an error

But I notice src/app/main.prod.ts having the error import { AppModuleNgFactory } from './app.module.ngfactory';

[ts] Cannot find module './app.module.ngfactory'.

How to solve this?

Hello, i have the same issue, attached the error stack

[09:38:27]  Error: Could not resolve entry (.tmp/app/main.prod.js)
    at /Users/koala/Documents/angular/tfc-mobile/node_modules/rollup/dist/rollup.js:8602:28

[09:38:27]  sass started ...
[09:38:31]  sass finished in 4.43 s
[09:38:31]  minify started ...
[09:38:31]  cleancss started ...
[09:38:31]  uglifyjs started ...
[09:38:31]  Error: ENOENT: no such file or directory, open '/Users/koala/Documents/angular/tfc-mobile/www/build/main.js'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at addFile (/Users/koala/Documents/angular/tfc-mobile/node_modules/uglify-js/tools/node.js:68:22)
    at /Users/koala/Documents/angular/tfc-mobile/node_modules/uglify-js/tools/node.js:79:17
    at Array.forEach (native)
    at Object.exports.minify (/Users/koala/Documents/angular/tfc-mobile/node_modules/uglify-js/tools/node.js:77:26)
    at runUglifyInternal (/Users/koala/Documents/angular/tfc-mobile/node_modules/@ionic/app-scripts/dist/uglifyjs.js:34:19)
    at runUglify (/Users/koala/Documents/angular/tfc-mobile/node_modules/@ionic/app-scripts/dist/uglifyjs.js:23:28)
    at Object.uglifyjs (/Users/koala/Documents/angular/tfc-mobile/node_modules/@ionic/app-scripts/dist/uglifyjs.js:9:12)

It works well if i run ionic serve, but got this error if i run ionic run android

any idea, thanks for the help.