Error during executing "ionic cordova run android --prod"

Hi,

Today i tried to run my ionic app on tablet.
After executing command ionic cordova run android --prod i am getting this error:

Running app-scripts build: --prod --address 0.0.0.0 --port 8100 --p 8100 --livereload-port 35729 --r 35729 --iscordovaserve --externalIpRequired --nobrowser

[14:15:42]  build prod started ...
[14:15:42]  clean started ...
[14:15:42]  clean finished in 38 ms
[14:15:42]  copy started ...
[14:15:42]  ngc started ...
[14:15:59]  ngc finished in 16.93 s
[14:15:59]  preprocess started ...
[14:15:59]  deeplinks started ...
[14:16:01]  deeplinks finished in 1.39 s
[14:16:01]  optimization started ...
[14:16:01]  copy finished in 18.73 s
[14:16:20]  optimization finished in 19.22 s
[14:16:20]  preprocess finished in 20.63 s
[14:16:20]  webpack started ...
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova).
Error: ./node_modules/ionic-native/dist/esm/plugins/plugin.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (C:\Users\***\node_modules\typescript\lib\typescript.js:9341:17)
    at assignContextualParameterTypes (C:\Users\***\node_modules\typescript\lib\typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (C:\Users\***\node_modules\typescript\lib\typescript.js:41948:29)
    at checkExpressionWorker (C:\Users\***\node_modules\typescript\lib\typescript.js:42959:28)
    at checkExpression (C:\Users\***\node_modules\typescript\lib\typescript.js:42898:42)
    at checkExpressionCached (C:\Users\***\node_modules\typescript\lib\typescript.js:42779:38)
    at checkReturnStatement (C:\Users\***\node_modules\typescript\lib\typescript.js:45418:54)
    at checkSourceElement (C:\Users\***\node_modules\typescript\lib\typescript.js:46763:28)
    at Object.forEach (C:\Users\***\node_modules\typescript\lib\typescript.js:1506:30)
    at checkBlock (C:\Users\***\node_modules\typescript\lib\typescript.js:44563:16)
 @ ./node_modules/ionic-native/dist/esm/index.js 233:0-33
 @ ./node_modules/@ionic/cloud/dist/esm/auth.js
 @ ./node_modules/@ionic/cloud/dist/esm/index.js
 @ ./node_modules/@ionic/cloud-angular/dist/esm/index.js
 @ ./src/app/app.component.ts
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts

Without –prod flag application is building properly (besides tslint “unsued import” error).

Result of ionic info command:

cli packages:

    @ionic/cli-plugin-cordova       : 1.5.0 (C:\Users\***\node_modules\@ionic\cli-plugin-cordova)
    @ionic/cli-plugin-ionic-angular : 1.4.0 (C:\Users\***\node_modules\@ionic\cli-plugin-ionic-angular)
    @ionic/cli-utils                : 1.6.0 (C:\Users\***\node_modules\@ionic\cli-utils)
    ionic (Ionic CLI)               : 3.6.0 (C:\Users\***\node_modules\ionic)

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.1.2
    Ionic Framework    : ionic-angular 3.6.0

System:

    Node : v8.1.2
    OS   : Windows 10
    npm  : 5.3.0

And my package.json file

 "dependencies": {
        "@angular/animations": "4.1.3",
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@angular/platform-server": "4.1.3",
        "@angular/router": "4.1.3",
        "@angular/tsc-wrapped": "4.1.3",
        "@ionic-native/core": "^4.1.0",
        "@ionic-native/device": "^4.1.0",
        "@ionic-native/in-app-browser": "^4.1.0",
        "@ionic-native/splash-screen": "^4.1.0",
        "@ionic-native/status-bar": "^4.1.0",
        "@ionic/cloud-angular": "^0.12.0",
        "@ionic/storage": "2.0.1",
        "angular2-jwt": "^0.2.3",
        "angular2-moment": "^1.6.0",
        "autoprefixer": "^7.1.2",
        "cordova-plugin-console": "^1.0.7",
        "cordova-plugin-device": "^1.1.6",
        "cordova-plugin-inappbrowser": "^1.7.1",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.3",
        "cordova-plugin-whitelist": "^1.3.2",
        "cordova-sqlite-storage": "^2.0.4",
        "ionic-angular": "^3.6.0",
        "ionic-plugin-deploy": "^0.6.7",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "moment": "^2.18.1",
        "rxjs": "5.4.2",
        "sw-toolbox": "3.6.0",
        "zone.js": "^0.8.16"
    },
    "devDependencies": {
        "@ionic/app-scripts": "2.1.3",
        "@ionic/cli-plugin-cordova": "1.5.0",
        "@ionic/cli-plugin-ionic-angular": "1.4.0",
        "ionic": "3.6.0",
        "typescript": "^2.4.2"
    },

Any ideas?

Any luck finding a solution for this?

Unfortunately no. I started new project and copied sorce code from the old one. I think this error occurred because I recently updated my project from Ionic 2 to Ionic 3…

I’m suffering with this too. I haven’t been able to build with --prod since updating from Ionic 2 to Ionic 3. It happens for me on both the iOS and Android builds. I’m using all the latest Ionic, Ionic Native, Cordova, and Typescript as well. I ran across this trying to solve building with --prod with using webpack and absolute import paths.

What is “this” in that sentence?

Post your ionic info and a complete output of your error please.

I ran across “this issue” - meaning this web page. Here is my relevant info.

Here are the relevant parts:

package.json:

    "dependencies": {
        "@angular/animations": "4.1.3",
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@angular/platform-server": "4.1.3",
        "@angular/router": "4.1.3",
        "@angular/tsc-wrapped": "4.2.5",
        "@ionic-native/core": "4.1.0",
        "@ionic-native/keyboard": "4.1.0",
        "@ionic-native/network": "4.1.0",
        "@ionic-native/screen-orientation": "4.1.0",
        "@ionic-native/splash-screen": "4.1.0",
        "@ionic-native/status-bar": "4.1.0",
        "@ionic/storage": "2.0.1",
        "cordova": "7.0.1",
        "cordova-android": "6.2.3",
        "cordova-ios": "4.4.0",
        "cordova-plugin-compat": "1.1.0",
        "cordova-plugin-console": "1.0.7",
        "cordova-plugin-device": "1.1.6",
        "cordova-plugin-file": "4.3.3",
        "cordova-plugin-ios-disableshaketoedit": "1.0.0",
        "cordova-plugin-keyboard": "1.1.5",
        "cordova-plugin-network-information": "1.3.3",
        "cordova-plugin-privacyscreen": "0.3.1",
        "cordova-plugin-screen-orientation": "https://github.com/Exilz/cordova-plugin-screen-orientation",
        "cordova-plugin-splashscreen": "4.0.3",
        "cordova-plugin-statusbar": "2.2.3",
        "cordova-plugin-whitelist": "1.3.2",
        "cordova-plugin-wkwebview-engine": "https://github.com/driftyco/cordova-plugin-wkwebview-engine",
        "core-js": "2.4.1",
        "es6-promise-plugin": "4.1.0",
        "ionic": "3.6.0",
        "ionic-angular": "3.6.0",
        "ionic-plugin-keyboard": "2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "5.4.2",
        "sw-toolbox": "3.6.0",
        "webpack": "3.1.0",
        "zone.js": "0.8.12"
    },
    "devDependencies": {
        "@ionic/app-scripts": "2.1.3",
        "@ionic/cli-plugin-cordova": "1.5.0",
        "@ionic/cli-plugin-ionic-angular": "1.4.0",
        "@ionic/cli-plugin-proxy": "1.4.0",
        "@types/angular": "1.6.25",
        "@types/ionic": "0.0.34",
        "@types/jasmine": "2.5.53",
        "@types/jest": "20.0.2",
        "@types/node": "6.0.60",
        "@types/sinon": "2.3.2",
        "codelyzer": "3.0.1",
        "fs": "0.0.1-security",
        "indexeddb-mock": "1.1.0",
        "jasmine-core": "2.6.2",
        "jasmine-spec-reporter": "4.1.0",
        "jest": "20.0.4",
        "jest-preset-angular": "2.0.4",
        "plist": "2.1.0",
        "protractor": "5.1.2",
        "rollup-plugin-replace": "1.1.1",
        "sinon": "2.3.5",
        "ts-node": "3.0.4",
        "tslint": "5.4.3",
        "typescript": "2.4.2"
    },
    "config": {
         "ionic_optimization": "./optimization.config.js",
        "ionic_webpack": "./webpack.config.js"
    }

optimization.config.js:

var path = require('path')
var webpack = require('webpack')
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY)

module.exports = {
  entry: process.env.IONIC_APP_ENTRY_POINT,
  output: {
    path: '{{BUILD}}',
    publicPath: 'build/',
    filename: 'deptree.js'
  },

  resolve: {
    extensions: ['.js', '.ts', '.tsx'],
    modules: [path.resolve('node_modules'), path.resolve('src')],
    alias: {
      environments: path.resolve('src/environments'),
      app: path.resolve('src/app'),
      lib: path.resolve('src/lib'),
      pages: path.resolve('src/pages'),
      components: path.resolve('src/components'),
      validators: path.resolve('src/validators'),
      providers: path.resolve('src/providers'),
      models: path.resolve('src/models'),
      decorators: path.resolve('src/decorators'),
      pipes: path.resolve('src/pipes')
    }
  },

  module: {
    loaders: [
      {
        test: /\.tsx?$/,
        loader: process.env.IONIC_OPTIMIZATION_LOADER
      },
      {
        test: /\.js$/,
        loader: process.env.IONIC_OPTIMIZATION_LOADER
      }
    ]
  },

  plugins: [
    ionicWebpackFactory.getIonicOptimizationEnvironmentPlugin()
  ],

  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
}

Ionic info:

cli packages:

    @ionic/cli-plugin-cordova       : 1.5.0
    @ionic/cli-plugin-ionic-angular : 1.4.0
    @ionic/cli-plugin-proxy         : 1.4.0
    @ionic/cli-utils                : 1.6.0
    ionic (Ionic CLI)               : 3.6.0

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.2.3 ios 4.4.0
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 26.0.2
    Node              : v8.1.4
    OS                : macOS Sierra
    Xcode             : Xcode 8.3.3 Build version 8E3004b
    ios-deploy        : 1.9.1
    ios-sim           : 6.0.0
    npm               : 5.0.3

Command run:
ionic cordova build ios --prod --no-interactive

Error:

npm WARN invalid config loglevel="notice"

Running app-scripts build: --build --prod --iscordovaserve --externalIpRequired --nobrowser

[15:10:44]  build prod started ...
[15:10:44]  clean started ...
[15:10:44]  clean finished in 1 ms
[15:10:44]  copy started ...
[15:10:44]  ngc started ...
[15:11:01]  ngc finished in 16.92 s
[15:11:01]  preprocess started ...
[15:11:01]  deeplinks started ...
[15:11:03]  deeplinks finished in 2.22 s
[15:11:03]  optimization started ...
[15:11:27]  optimization finished in 23.28 s
[15:11:27]  preprocess finished in 25.50 s
[15:11:27]  webpack started ...
[15:13:46]  copy finished in 181.57 s
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova).
Error: ./node_modules/ionic-native/dist/esm/plugins/plugin.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (/xxx/node_modules/typescript/lib/typescript.js:9341:17)
    at assignContextualParameterTypes (/xxx/node_modules/typescript/lib/typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (/xxx/node_modules/typescript/lib/typescript.js:41948:29)
    at checkExpressionWorker (/xxx/node_modules/typescript/lib/typescript.js:42959:28)
    at checkExpression (/xxx/node_modules/typescript/lib/typescript.js:42898:42)
    at checkExpressionCached (/xxx/node_modules/typescript/lib/typescript.js:42779:38)
    at checkReturnStatement (/xxx/node_modules/typescript/lib/typescript.js:45418:54)
    at checkSourceElement (/xxx/node_modules/typescript/lib/typescript.js:46763:28)
    at Object.forEach (/xxx/node_modules/typescript/lib/typescript.js:1506:30)
    at checkBlock (/xxx/node_modules/typescript/lib/typescript.js:44563:16)
 @ ./node_modules/ionic-native/dist/esm/index.js 233:0-33
 @ ./node_modules/@ionic/cloud/dist/es5/di.js
 @ ./src/app/app.module.ngfactory.js
 @ ./src/app/main.ts
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Foo@ build-ios-qa: `ionic cordova build ios --prod --no-interactive`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Foo@ build-ios-qa script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./src",
    "paths": {
      "environments/*": [
        "./environments/*"
      ],
      "app/*": [
        "./app/*"
      ],
      "lib/*": [
        "./lib/*"
      ],
      "pages/*": [
        "./pages/*"
      ],
      "components/*": [
        "./components/*"
      ],
      "validators/*": [
        "./validators/*"
      ],
      "providers/*": [
        "./providers/*"
      ],
      "models/*": [
        "./models/*"
      ],
      "decorators/*": [
        "./decorators/*"
      ],
      "pipes/*": [
        "./pipes/*"
      ]
    },
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "noStrictGenericChecks": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "jasmine",
      "sinon"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

webpack.config.js

var path = require('path')
var webpack = require('webpack')
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY)

var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin')

var prodPlugins = []
if (process.env.IONIC_ENV === 'prod') {
  prodPlugins.push(new ModuleConcatPlugin())
}

var env = process.env.NODE_ENV || 'dev'

console.log('------------------------')
console.log('environment:', env)
console.log('------------------------')

module.exports = {
  entry: process.env.IONIC_APP_ENTRY_POINT,
  output: {
    path: '{{BUILD}}',
    publicPath: 'build/',
    filename: '[name].js',
    devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
  },
  devtool: process.env.IONIC_SOURCE_MAP_TYPE,

  resolve: {
    extensions: ['.js', '.json', '.ts', '.tsx'],
    modules: [path.resolve('node_modules'), path.resolve('src')],
    alias: {
      environments: path.resolve('src/environments'),
      app: path.resolve('src/app'),
      lib: path.resolve('src/lib'),
      pages: path.resolve('src/pages'),
      components: path.resolve('src/components'),
      validators: path.resolve('src/validators'),
      providers: path.resolve('src/providers'),
      models: path.resolve('src/models'),
      decorators: path.resolve('src/decorators'),
      pipes: path.resolve('src/pipes')
    }
  },

  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.tsx?$/,
        loader: process.env.IONIC_WEBPACK_LOADER
      },
      {
        test: /\.js$/,
        loader: process.env.IONIC_WEBPACK_TRANSPILE_LOADER
      }
    ]
  },

  plugins: [
    ionicWebpackFactory.getIonicEnvironmentPlugin(),
    ionicWebpackFactory.getCommonChunksPlugin(),
    new webpack.DefinePlugin({
      TA_ENV: {environment: JSON.stringify(env)}
    })
  ].concat(prodPlugins),

  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
}

Update: I think I’ve figured out this problem. I had to remove some unused code related to using:
import { CloudModule, CloudSettings } from '@ionic/cloud-angular'.

1 Like

5 posts were split to a new topic: Error: ./~/ionic-native/dist/esm/plugins/plugin.js Module build failed: TypeError: Cannot read property ‘type’ of undefined