Ionic build fails with Error: Cannot find module '../cordova/platform_metadata'

My Ionic project fails with the following error and searched a lot but unable to resolve. FOllowing is the complete output i get on ionic cordova build android

G:\Development\ionic\RoTheCi\app>ionic cordova run android
Running app-scripts build: --platform android --target cordova
[19:09:25]  build dev started ...
[19:09:26]  clean started ...
[19:09:26]  clean finished in 26 ms
[19:09:26]  copy started ...
[19:09:26]  deeplinks started ...
[19:09:27]  deeplinks finished in 810 ms
[19:09:27]  transpile started ...
[19:09:50]  transpile finished in 22.94 s
[19:09:50]  preprocess started ...
[19:09:50]  preprocess finished in 4 ms
[19:09:50]  webpack started ...
[19:09:51]  copy finished in 24.90 s
[19:10:34]  webpack finished in 43.83 s
[19:10:34]  sass started ...
[19:10:41]  sass finished in 7.12 s
[19:10:41]  postprocess started ...
[19:10:41]  postprocess finished in 37 ms
[19:10:41]  lint started ...
[19:10:41]  build dev finished in 75.48 s
> cordova run android
Android Studio project detected

(node:7800) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot find module '../cordova/platform_metadata'

[OK] Your app has been deployed.
     Did you know you can live-reload changes from your app with --livereload?

[19:11:02]  tslint: .../Development/ionic/RobTheCity/app/node_modules/ng-socket-io/socket-io.service.ts, line: 1
            'Injectable' is declared but never used.

       L1:  import { Injectable, Inject } from '@angular/core';
       L2:  import { Observable } from 'rxjs/Observable';

[19:11:02]  tslint: G:/Development/ionic/RobTheCity/app/src/pages/rob/rob.ts, line: 13
            'AttemptResp' is declared but never used.

      L13:  interface AttemptResp {
      L14:    id?: string;

[19:11:02]  tslint: G:/Development/ionic/RobTheCity/app/src/pages/modal-defense/modal-defense.ts, line: 12
            All imports are unused.

      L12:  import differenceInSeconds from 'date-fns/difference_in_seconds';

[19:11:02]  tslint: ...ment/ionic/RobTheCity/app/src/providers/http-error-handler/http-error-handler.ts, line: 21
            'error' is declared but never used.

      L21:      private error(error: Response | any) {
      L22:          let errMsg = '';

[19:11:02]  tslint: G:/Development/ionic/RobTheCity/app/src/app/app.module.ts, line: 16
            All imports are unused.

      L15:  import { FCM } from '@ionic-native/fcm';
      L16:  import { Config } from '../config/config';
      L17:  const ioConfig: SocketIoConfig = {

[19:11:02]  lint finished in 20.82 s

G:\Development\ionic\RobTheCity\app>

My Ionic info is

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

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 8.0.0

local packages:

    @ionic/app-scripts : 3.1.6
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 25.2.3
    Node              : v6.9.1
    npm               : 4.6.1
    OS                : Windows 8.1

Environment Variables:

    ANDROID_HOME : C:\Users\Public

Misc:

    backend : pro

I am not able to find the root cause of the issue, I installed angularfire2 and firebase that resulted into some issues, as I uninstalled firebase and angularfire2, this issue came out of nowhere.

4 Likes

Same Here I downgraded Cordova to 7.1.0 until this is fixed

6 Likes

Yep, was going to post that too.

So:

npm uninstall -g cordova
npm install -g cordova@7.1.0
8 Likes

yep the issue goes away but another error occured

Error: Invalid data, chunk must be a string or buffer, not object

I resolved it by running

ionic cordova platform remove android
ionic cordova platform add android

so,

npm uninstall -g cordova
npm install -g cordova@7.1.0
ionic cordova platform remove android
ionic cordova platform add android
8 Likes

Hey yall! Taking a look at this!

5 Likes

Hello, i have been getting the same issue in version 8.0.0 when building iOS or adding iOS platform:

Error below is shown:

(node:10273) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot find module ‘…/cordova/platform_metadata’
(node:10273) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can anyone here tell me if they’re using the cordova-plugin-ionic for ionic pro and having this?

2 Likes

Yes, I have the following plugin in my project:
“cordova-plugin-ionic”: “^2.0.4”, not using ionic pro though

Alright, I have found the issue in a plugin. PR has been sent, hang tight folks!

3 Likes

Will it be available through npm install?

Same issue here too. I guess it doesn’t yet support Cordova CLI 8.0

Been stuck for days, your answer saved me!
Thank you :smile:

1 Like

Hi folks! Happy to share that the swift plugin has been updated and released. You can remove the cordova-plugin-ionic and add it back to get the update

3 Likes

Thanks Mike - that worked for me!

Ehm… thanks Mike, but the original comment was about Android, not iOS/Swift. I had the same issue and (npm) uninstall and (re)install of cordova-plugin-ionic didn’t help me. I had to downgrade to Cordova 7.1.x.

2 Likes

Had same problems here, at cordova 8.0.0, ios platform

ionic cordova plugin add cordova-plugin-ionic --variable APP_ID=****** --variable CHANNEL_NAME=Production
> cordova plugin add cordova-plugin-ionic --variable APP_ID=****** --variable CHANNEL_NAME=Production --save
Installing "cordova-plugin-ionic" for ios

Plugin dependency "cordova-plugin-add-swift-support@1.7.0" already fetched, using that version.

Dependent plugin "cordova-plugin-add-swift-support" already installed on ios.

Failed to install 'cordova-plugin-ionic': CordovaError: Version of installed plugin: "cordova-plugin-splashscreen@5.0.1" does not satisfy dependency plugin requirement "cordova-plugin-splashscreen@^4.0.0". Try --force to use installed plugin as dependency.

ionic cordova plugin add cordova-plugin-ionic --variable APP_ID=***** --variable CHANNEL_NAME=Production --force
> cordova plugin add cordova-plugin-ionic --force --variable APP_ID=***** --variable CHANNEL_NAME=Production --save
Installing "cordova-plugin-ionic" for ios

Plugin dependency "cordova-plugin-add-swift-support@1.7.0" already fetched, using that version.

Dependent plugin "cordova-plugin-add-swift-support" already installed on ios.

Plugin dependency "cordova-plugin-splashscreen@5.0.1" already fetched, using that version.

Dependent plugin "cordova-plugin-splashscreen" already installed on ios.

Adding cordova-plugin-ionic to package.json

Saved plugin info for "cordova-plugin-ionic" to config.xml

(node:5870) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot find module '../cordova/platform_metadata'
(node:5870) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

downgrade to 7.1.0 solve problem

1 Like

I was struggling with this issue and found that the following method worked:

ionic cordova plugin remove cordova-plugin-ionic
ionic cordova plugin add cordova-plugin-ionic --save … failed with following error:
Unmet project requirements for latest version of cordova-plugin-ionic:

cordova-plugin-splashscreen (4.0.3 in project, >=5.0.1 required)

I solved this by doing:
ionic cordova plugin remove cordova-plugin-splashscreen

adding the cordova-plugin-ionic again installed the newer version of cordova-plugin-splashscreen and the error is gone.

2 Likes

Just in case anyone else runs into the same problem as I did, The plugin cordova-plugin-swift-support was in my project not cordova-plugin-add-swift-support to fix I did

ionic cordova platforms rm ios
ionic cordova plugins rm cordova-plugin-swift-support
ionic cordova plugins add cordova-plugin-add-swift-support
ionic cordova platforms add ios
1 Like

This is still an issue with Cordova8.0.0

3 Likes

Hi Guys i have also facing same problem. Please Help to me.

I have created new Ionic 4 project and integrated geofence.

Just installed this plugin and run. I have facing this error.

Cannot find module '…/…/src/cordova/platform_metadata’

My Ionic info

Ionic:

Ionic CLI : 5.2.2

Utility:

cordova-res : not installed
native-run : 0.2.7

System:

NodeJS : v10.16.0
npm : 6.9.0
OS : Windows 10

Package.json

{
  "name": "geofence-app",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^7.2.2",
    "@angular/core": "^7.2.2",
    "@angular/forms": "^7.2.2",
    "@angular/http": "^7.2.2",
    "@angular/platform-browser": "^7.2.2",
    "@angular/platform-browser-dynamic": "^7.2.2",
    "@angular/router": "^7.2.2",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/geofence": "^5.10.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.1.0",
    "cordova-android": "7.0.0",
    "cordova-plugin-add-swift-support": "^1.6.0",
    "cordova-plugin-androidx": "^1.0.2",
    "cordova-plugin-androidx-adapter": "^1.1.0",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-geofence": "^0.7.0",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^4.1.1",
    "cordova-plugin-splashscreen": "^5.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-whitelist": "^1.3.4",
    "core-js": "^2.5.4",
    "es6-promise-plugin": "^4.2.2",
    "rxjs": "~6.5.1",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.29"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.13.8",
    "@angular-devkit/build-angular": "~0.13.8",
    "@angular-devkit/core": "~7.3.8",
    "@angular-devkit/schematics": "~7.3.8",
    "@angular/cli": "~7.3.8",
    "@angular/compiler": "~7.2.2",
    "@angular/compiler-cli": "~7.2.2",
    "@angular/language-service": "~7.2.2",
    "@ionic/angular-toolkit": "~1.5.1",
    "@ionic/lab": "2.0.6",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~12.0.0",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~8.3.0",
    "tslint": "~5.17.0",
    "typescript": "~3.1.6"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-geofence": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-androidx": {},
      "cordova-plugin-androidx-adapter": {},
      "cordova-plugin-add-swift-support": {}
    },
    "platforms": [
      "android"
    ]
  }
}

I have stuck this error in last one week. Still not find any solution.

@mhartington @imdadturi @Alberthoekstra

Give some idea to solve this issue.