question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cordova 10 error when adding or removing platform

See original GitHub issue

Bug Report

Problem

Updating an existing project from Cordova 9 to 10, I get an error when trying to add or remove a platform. Then tried with new Ionic project in clean Node installation, and get the same error.

What is expected to happen?

> cordova platform add android

The Android platform is added to the project.

> cordova platform remove android

The Android platform is removed from the project (or a message saying it’s not part of the project).

What does actually happen?

ncumpstey@Apps-MBP test % cordova platform add android --verbose
No scripts found for hook "before_platform_add".
No version supplied. Retrieving version from config.xml...
Grabbing pinned version.
Using cordova-fetch for cordova-android@^9.0.0
fetch: Installing cordova-android@^9.0.0 to /Users/ncumpstey/Documents/Projects/test
Failed to fetch platform cordova-android@^9.0.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
CordovaError: TypeError: Cannot assign to read only property 'valueOf' of object '[object Object]'
CordovaError: Failed to fetch platform cordova-android@^9.0.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
CordovaError: TypeError: Cannot assign to read only property 'valueOf' of object '[object Object]'
    at /Users/ncumpstey/.nvm/versions/node/v12.20.0/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/platform/addHelper.js:288:31
ncumpstey@Apps-MBP test % cordova platform remove android --verbose
No scripts found for hook "before_platform_rm".
Removing platform android from platforms.json file...
TypeError: Cannot assign to read only property 'valueOf' of object '[object Object]'
    at Function.defer (/Users/ncumpstey/.nvm/versions/node/v12.20.0/lib/node_modules/cordova/node_modules/q/q.js:576:21)
    at Object.exports.spawn (/Users/ncumpstey/.nvm/versions/node/v12.20.0/lib/node_modules/cordova/node_modules/cordova-common/src/superspawn.js:64:17)
    at /Users/ncumpstey/.nvm/versions/node/v12.20.0/lib/node_modules/cordova/node_modules/cordova-fetch/index.js:177:31
CordovaError: TypeError: Cannot assign to read only property 'valueOf' of object '[object Object]'
    at /Users/ncumpstey/.nvm/versions/node/v12.20.0/lib/node_modules/cordova/node_modules/cordova-fetch/index.js:180:19

Information

Command or Code

> cordova platform add android
> cordova platform remove android

Environment, Platform, Device

Mac

Version information

MacOS 10.15.7 Node 12.20.0 and 10.15.3 - same behaviour in both. Cordova CLI 10.0.0 Ionic CLI 6.12.2

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
breautekcommented, Nov 25, 2020

Problem appears to be coming from a sub-dependency.

My first guess is that a sub-dependency didn’t get updated properly on your upgrade. This can happen sometimes when doing upgrades because of how NPM and package locks work…

Can you try the following:

  1. Delete node_modules folder
  2. Delete platforms folder - Read the note below
  3. Delete plugins folder
  4. Delete package-lock.json file

If you use a global cordova installation, then do: npm uninstall -g cordova && npm install -g cordova

  1. run npm install
  2. run cordova platform add android

The above will forcefully remove all your dependencies, platforms and plugins. If you made any custom modifications to your platform(s), it is important you backup those changes.. Then, it will reinstall your dependencies. The platform add command will restore your cordova plugins. The result is everything is installed from scratch.

Let me know if this helps.

4reactions
RianFurocommented, Nov 25, 2020

Glad I could help clear this up 🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to update Cordova Platforms to android@10 - Ionic Forum
i'm trying to update cordova platform in my ionic application from android@9 to android@10 ionic cordova platform remove android ionic ...
Read more >
Cordova CLI 10.0.0 Released!
Removed the plugin save command, which had become the default behaviour since version 7.0. Improved cordova info display. Raised the minimum ...
Read more >
How to solve this errors Ant, add platform android and cordova ...
Your error log says "Unable to resolve project target 'android-21'" which means your sdk dont have specific target, do this - after downloading ......
Read more >
Adding the MobileFirst Foundation SDK to Cordova Applications
Note: The cordova-windows latest published version has a bug, which will throw an exception during app launch. Apache Cordova has fixed the ...
Read more >
cordova plugins installation error - SAP Community
directory and also have added android with cordova command , but when i try to install odata plugin it gives me error ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found