Error building an android apk -TypeError: Object prototype may only be an Object or null: undefined at setPrototypeOf (<anonymous>)


I would like assitance with this error if anyone has seen it before.

I am trying to run ionic cordova build android --prod and its giving me this error

[13:55:15]  build prod started ...
[13:55:16]  clean started ...
[13:55:16]  clean finished in 10 ms
[13:55:16]  copy started ...
[13:55:17]  deeplinks started ...
[13:55:18]  deeplinks finished in 300 ms
[13:55:18]  ngc started ...
TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at Object.__extends (C:\mydir\node_modules\tslib\tslib.js:64:9)
    at C:\MobileApps2019\MUFSASFINAL\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:115:17
    at C:\mydir\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:314:6
    at Object.defineProperty.value (C:\mydir\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:3:17)
    at Object.<anonymous> (C:\mydir\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:9:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

Here is my ionic info data

cli packages: (C:\Users\admin\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.3
    ionic (Ionic CLI) : 3.20.1

global packages:

    cordova (Cordova CLI) : 9.0.0 (cordova-lib@9.0.1)

local packages:

    @ionic/app-scripts : 3.2.4
    Cordova Platforms  : none
    Ionic Framework    : ionic-angular 3.9.2


    Android SDK Tools : 26.1.1
    Node              : v8.11.3
    npm               : 6.10.2
    OS                : Windows 10

Environment Variables:

    ANDROID_HOME : C:\Users\admin\AppData\Local\Android\Sdk


Hi, were you able to solve this ?

Yes, I this I sorted it by deleting the node module folder and ran npm install.

I have the same problem. My info:


Ionic CLI : 5.2.4 (C:\Users\User\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.4


Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : not available
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, (and 17 other plugins)


cordova-res : 0.6.0
native-run : not installed


Android SDK Tools : 26.1.1 (C:\Users\User\AppData\Local\Android\Sdk)
NodeJS : v10.15.1 (C:\Program Files\nodejs\node.exe)
npm : 6.4.1
OS : Windows 10

but I also run with command: ionic cordova build android --prod --release – -- --keystore=filename.keystore --alias=myalias .
But when I run without --prod already ok.

the problem comes from the compilation with angular, create a new project with ionic version 3, then compare the files packages.json.

1 Like

So, following @goku-dev’s answer, I could solve and this are the steps to solve:

  1. Create a new project with ionic version 3, then compare the files packages.json.
ionic start Ionic3Project blank --type=ionic-angular
  1. Inside Ionic3Project folder, build android
ionic cordova build android --prod
  1. Open the packages.json of your main project and change the following versions of dependencies:
Also, replace the "scripts" part.
  1. Delete your node_modules folder.

  2. Delete your platform android folder (the entire platform folder or just android folder).

  3. Run npm install

  4. Add platform android

ionic cordova platform add android
  1. Build your app again
ionic cordova build android --prod

After follow these steps, I could build my app again.

Obs.: It’s possible you got some issues related to plugins between these steps. In this case, you might need re-install the plugin(s). Do it and keep those steps in mind. Try to remove and re-add android after re-install the plugins.

I have faced the same issue, got npm audit fix suggestion from npm cmd prompt, done that too but issue not solved, then I removed node-modules, then npm i, this time i haven’t run npm audit fix, then I again run ionic cordova build android --prod
Run successfully

1 Like