How do I update to Cordova 12 in Ionic 3? (Camera problem)

I’m trying to update my ionic 3 app to uses cordova 12. Is that possible?

Google Play Store required me to update the android-targetSdkVersion from 31 to 33. As a result, the camera opening functionality stopped working on newer devices (such as Android 11 and 12).

This topic sugests that I need to update to cordova-android version 12 because earlier versions no longer support the camera: Camera not working when Target SDK 33

So I try to run:

cordova platform remove android
cordova platform add android@12.0.0

Using Node v6.17.1 and npm v3.10.10:

AppData\Roaming\npm\node_modules\cordova\node_modules\nopt\lib\nopt-lib.js:64
  const StringType = typeDefs.String?.type (SyntaxError: Unexpected token .)

Using Node v18.18.0 and npm v9.8.1:

Failed to fetch platform cordova-android@12.0.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
CordovaError: Error: Command failed with exit code 1: npm install cordova-android@12.0.0 --save-dev
npm WARN idealTree Removing dependencies.cordova-android in favor of devDependencies.cordova-android
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @angular/compiler-cli@4.4.4
npm ERR! Found: typescript@3.7.7
npm ERR! node_modules/typescript
npm ERR!   peer typescript@">=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >=3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev" from tslint@5.20.1
npm ERR!   node_modules/tslint
npm ERR!     peer tslint@"^5.0.0" from tslint-eslint-rules@4.1.1
npm ERR!     node_modules/tslint-eslint-rules
npm ERR!       tslint-eslint-rules@"4.1.1" from @ionic/app-scripts@3.0.1
npm ERR!       node_modules/@ionic/app-scripts
npm ERR!         dev @ionic/app-scripts@"3.0.1" from the root project
npm ERR!     tslint@"^5.5.0" from @ionic/app-scripts@3.0.1
npm ERR!     node_modules/@ionic/app-scripts
npm ERR!       dev @ionic/app-scripts@"3.0.1" from the root project
npm ERR!   peer typescript@">=2.0.0 || >=2.0.0-dev || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >= 2.4.0-dev" from tsutils@1.9.1
npm ERR!   node_modules/tslint-eslint-rules/node_modules/tsutils
npm ERR!     tsutils@"^1.4.0" from tslint-eslint-rules@4.1.1
npm ERR!     node_modules/tslint-eslint-rules
npm ERR!       tslint-eslint-rules@"4.1.1" from @ionic/app-scripts@3.0.1
npm ERR!       node_modules/@ionic/app-scripts
npm ERR!         dev @ionic/app-scripts@"3.0.1" from the root project
npm ERR!   2 more (tsutils, the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@"^2.0.2" from @angular/compiler-cli@4.4.4
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"4.4.4" from ionic-angular@3.8.0
npm ERR!   node_modules/ionic-angular
npm ERR!     ionic-angular@"3.8.0" from the root project
npm ERR!   @angular/compiler-cli@"4.4.4" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: typescript@2.9.2
npm ERR! node_modules/typescript
npm ERR!   peer typescript@"^2.0.2" from @angular/compiler-cli@4.4.4
npm ERR!   node_modules/@angular/compiler-cli
npm ERR!     peer @angular/compiler-cli@"4.4.4" from ionic-angular@3.8.0
npm ERR!     node_modules/ionic-angular
npm ERR!       ionic-angular@"3.8.0" from the root project
npm ERR!     @angular/compiler-cli@"4.4.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! \AppData\Local\npm-cache\_logs\2023-09-19T20_26_09_921Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: \AppData\Local\npm-cache\_logs\2023-

My package.json:

{
    "name": "app",
    "version": "0.0.18",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build --prod",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "4.4.4",
        "@angular/compiler": "4.4.4",
        "@angular/compiler-cli": "4.4.4",
        "@angular/core": "4.4.4",
        "@angular/forms": "4.4.4",
        "@angular/http": "4.4.4",
        "@angular/platform-browser": "4.4.4",
        "@angular/platform-browser-dynamic": "4.4.4",
        "@ionic-native/app-version": "^4.20.0",
        "@ionic-native/camera": "^4.5.2",
        "@ionic-native/core": "^4.11.0",
        "@ionic-native/date-picker": "^4.20.0",
        "@ionic-native/geolocation": "^4.20.0",
        "@ionic-native/splash-screen": "4.3.2",
        "@ionic-native/status-bar": "4.3.2",
        "@ionic-native/vibration": "^4.20.0",
        "@ionic/storage": "2.0.1",
        "brmasker-ionic-3": "^1.6.3",
        "cordova-android": "^6.3.0",
        "cordova-custom-config": "^5.1.1",
        "cordova-ios": "^4.4.0",
        "cordova-plugin-app-version": "^0.1.14",
        "cordova-plugin-camera": "^4.0.2",
        "cordova-plugin-compat": "^1.2.0",
        "cordova-plugin-datepicker": "^0.9.3",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-geolocation": "~2.4.3",
        "cordova-plugin-ionic-webview": "^1.1.16",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-vibration": "^2.1.6",
        "cordova-plugin-whitelist": "^1.3.1",
        "ion": "^1.0.1",
        "ionic-angular": "3.8.0",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "^5.5.11",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.18"
    },
    "devDependencies": {
        "@ionic/app-scripts": "3.0.1",
        "typescript": "3.7.7"
    },
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-vibration": {},
            "cordova-plugin-datepicker": {},
            "cordova-plugin-device": {},
            "cordova-plugin-ionic-webview": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-plugin-geolocation": {
                "GEOLOCATION_USAGE_DESCRIPTION": " "
            },
            "cordova-plugin-camera": {},
            "cordova-plugin-compat": {},
            "cordova-custom-config": {},
            "cordova-plugin-app-version": {}
        },
        "platforms": [
            "android"
        ]
    }
}

For the first error you have to update node as latest cordova require node 16+
But since npm 7, if there are problems with peer dependencies, npm install fails, that’s your second problem.

You can try to fix the peer dependency problems.
In example, you have typescript 3.7 installed, but @angular/compiler-cli@4.4.4 requires typescript 2.x.
So you can downgrade typescript to 2.x or update @angular/compiler-cli to a newer version, and continue updating/downgrading things until it stops complaining.

Alternatively, you can install with npm install --force or npm install --legacy-peer-deps as the error is telling you at the end.

1 Like

Thanks. After many errors and version tests, I managed to update to Cordova 12 using the package.json and ionic info that I’m sending here.

Unfortunately, I can’t build Android platform due to plugins errors, which I reported in another thread: Plugins errors after update cordova-android to 12

My package.json:

{
“name”: “app”,
“version”: “0.0.18”,
“author”: “Ionic Framework”,
“homepage”: “http://ionicframework.com/”,
“private”: true,
“scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build --prod”,
“lint”: “ionic-app-scripts lint”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve”
},
“dependencies”: {
@angular/common”: “4.4.7”,
@angular/compiler”: “4.4.7”,
@angular/compiler-cli”: “4.4.7”,
@angular/core”: “4.4.7”,
@angular/forms”: “4.4.7”,
@angular/http”: “4.4.7”,
@angular/platform-browser”: “4.4.7”,
@angular/platform-browser-dynamic”: “4.4.7”,
@ionic-native/app-version”: “^4.20.0”,
@ionic-native/camera”: “^4.5.2”,
@ionic-native/core”: “^4.11.0”,
@ionic-native/date-picker”: “^4.20.0”,
@ionic-native/geolocation”: “^4.20.0”,
@ionic-native/splash-screen”: “4.3.2”,
@ionic-native/status-bar”: “4.3.2”,
@ionic-native/vibration”: “^4.20.0”,
@ionic/storage”: “2.0.1”,
“brmasker-ionic-3”: “^1.6.3”,
“cordova-android”: “^12.0.0”,
“cordova-custom-config”: “^5.1.1”,
“cordova-ios”: “^4.4.0”,
“cordova-plugin-app-version”: “^0.1.14”,
“cordova-plugin-camera”: “^4.0.2”,
“cordova-plugin-compat”: “^1.2.0”,
“cordova-plugin-datepicker”: “^0.9.3”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-geolocation”: “~2.4.3”,
“cordova-plugin-ionic-webview”: “^1.1.16”,
“cordova-plugin-splashscreen”: “^4.0.3”,
“cordova-plugin-vibration”: “^2.1.6”,
“cordova-plugin-whitelist”: “^1.3.1”,
“ion”: “^1.0.1”,
“ionic-angular”: “3.9.2”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“node-gyp”: “^9.4.0”,
“rxjs”: “^5.5.11”,
“sw-toolbox”: “3.6.0”,
“zone.js”: “0.8.18”
},
“devDependencies”: {
@ionic/app-scripts”: “3.0.1”,
“node-sass”: “7.0.3”,
“typescript”: “2.3.4”
},
“description”: “An Ionic project”,
“cordova”: {
“plugins”: {
“cordova-plugin-vibration”: {},
“cordova-plugin-datepicker”: {},
“cordova-plugin-device”: {},
“cordova-plugin-ionic-webview”: {},
“cordova-plugin-splashscreen”: {},
“cordova-plugin-whitelist”: {},
“ionic-plugin-keyboard”: {},
“cordova-plugin-geolocation”: {
“GEOLOCATION_USAGE_DESCRIPTION”: " "
},
“cordova-plugin-camera”: {},
“cordova-plugin-compat”: {},
“cordova-custom-config”: {},
“cordova-plugin-app-version”: {}
},
“platforms”: [
“android”
]
}
}

Ionic info:

Ionic:

ionic (Ionic CLI) : 4.0.0-rc.13 (C:\Users\Victor\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.0.1

Cordova:

cordova (Cordova CLI) : not installed
Cordova Platforms : android broken

System:

NodeJS : v17.9.1 (C:\Program Files\nodejs\node.exe)
npm : 8.11.0
OS : Windows 10

Environment:

ANDROID_HOME : not set