Failing Production Build of Ionic-3 app

#1

Hi,
I am building an app using Ionic-3. I am using follwing command to build the app -
ionic cordova build android --prod
When app starts it throws follwing error -
Uncaught Error: Cannot find module "."
** at vendor.js:1**
** at vendor.js:1**
** at Object. (vendor.js:1)**

However when I build without “–prod” flag, app build just fine.

Here is my package.json file:
Package.json -

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.2.9",
    "@angular/compiler": "5.2.9",
    "@angular/compiler-cli": "5.2.9",
    "@angular/core": "5.2.9",
    "@angular/forms": "5.2.9",
    "@angular/http": "5.2.9",
    "@angular/platform-browser": "5.2.9",
    "@angular/platform-browser-dynamic": "5.2.9",
    "@ionic-native/camera": "4.7.0",
    "@ionic-native/core": "4.7.0",
    "@ionic-native/device": "4.7.0",
    "@ionic-native/firebase": "4.7.0",
    "@ionic-native/in-app-browser": "4.7.0",
    "@ionic-native/keyboard": "4.7.0",
    "@ionic-native/push": "4.7.0",
    "@ionic-native/social-sharing": "4.7.0",
    "@ionic-native/splash-screen": "4.7.0",
    "@ionic-native/status-bar": "4.7.0",
    "@ionic/storage": "2.1.3",
    "@journeyapps/cordova-plugin-broadcaster": "file:cordova-plugin-broadcaster",
    "Applozic-Cordova-Ionic-PhoneGap-Chat-Plugin": "file:Applozic-Cordova-Ionic-PhoneGap-Chat-Plugin-master",
    "angularfire2": "^5.0.0-rc.6.0",
    "com.applozic.phonegap": "Applozic-Cordova-Ionic-PhoneGap-Chat-Plugin-master",
    "com.razorpay.cordova": "file:razorpay-cordova-master",
    "cordova-android": "6.4.0",
    "cordova-ios": "4.5.4",
    "cordova-plugin-broadcaster": "cordova-plugin-broadcaster",
    "cordova-plugin-camera": "^2.4.1",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-console": "^1.1.0",
    "cordova-plugin-device": "^1.1.7",
    "cordova-plugin-firebase": "file:cordova-plugin-firebase",
    "cordova-plugin-inappbrowser": "^1.7.2",
    "cordova-plugin-splashscreen": "^4.1.0",
    "cordova-plugin-statusbar": "^2.4.1",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-plugin-x-socialsharing": "^5.3.2",
    "es6-promise-plugin": "^4.2.2",
    "firebase": "4.12.1",
    "ionic-angular": "3.9.2",
    "ionic-img-viewer": "^2.4.0",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "jquery": "^3.2.1",
    "moment": "^2.21.0",
    "ng2-translate": "^5.0.0",
    "promise-polyfill": "^6.1.0",
    "rxjs": "5.5.2",
    "socket.io-client": "^2.0.1",
    "sw-toolbox": "3.6.0",
    "underscore": "^1.8.3",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^3.1.8",
    "@types/jquery": "^2.0.49",
    "@types/underscore": "^1.8.8",
    "typescript": "^2.7.2"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist"
  ],
  "cordovaPlatforms": [],
  "description": "app2: An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-console": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-compat": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-camera": {},
      "cordova-plugin-device": {},
      "cordova-plugin-inappbrowser": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-splashscreen": {},
      "com.razorpay.cordova": {},
      "cordova-plugin-x-socialsharing": {},
      "cordova-plugin-broadcaster": {},
      "com.applozic.phonegap": {},
      "cordova-plugin-firebase": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }
}

I tried some solution by downgrading the Typescript version -
~2.6.6 but not worked for me .

I feel that it may be related to app-script downloaded dependencies. And one of them not backward compatible. Not sure though.

Please help ??

#2

What are the dependencies if you start a new app right now? Make sure yours match those - those are “known good” for Ionic apps.

#3

Hi Sujan , what do you mean by dependency of a new app ? i have existing project and was working well till last build.

#4

You could use the below command to get a release build.

ionic cordova build android --minifycss --optimizejs --minifyjs --release

prod internally uses these but there seems to be a problem in aot(Ahead Of Time) complication / email pattern matching issue and it causes build failure.

#5

Start a new project with ionic start, then compare the package.json to what you have. If one of your dependencies are newer than what the new app got, you are too far and it is probably not supported by Ionic (yet).

#6

Hey Thanks Man !!! it helps me out … :slight_smile: