Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading cordova version from 8.x.x to 9.0.0 cordova build is failing #498

Closed
3 tasks
bandhavya opened this issue Jan 1, 2020 · 9 comments
Closed
3 tasks

Comments

@bandhavya
Copy link

Bug Report

On updating the cordova to 9.0.0 version, cordova build is failing with the below error

Problem

Unable to load PlatformApi from platform. Error: Cannot find module 'properties-parser' Unhandled error. (The platform "android" does not appear to be a valid cordova platform. It is missing API.js. android not supported.)

What is expected to happen?

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

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

breautek commented Jan 1, 2020

You may need to also update cordova-android.

You can do so by running the following commands:

cordova platform remove android
cordova platform add android@latest

The latest cordova-android version as of writing is 8.1.0

@bandhavya
Copy link
Author

@breautek
I have used [email protected]
Still this issue persists.

@brody4hire
Copy link

I wonder if something may have gone wrong on your file system (this happened to me once).

I recommend that you try the following:

  • Create a fresh, brand new Cordova project elsewhere in your file system and try running it on Android
  • Then start with a fresh copy of your project elsewhere in your file system, with no plugins or platforms included, then add and run the android platform.

I do think it would be good if Cordova could make this issue easier to troubleshoot (somehow).

@bandhavya
Copy link
Author

bandhavya commented Jan 1, 2020

@brodybits , @breautek
I got to know the root cause of this issue.

Steps to replicate :

  1. create a sample cordova app
  2. add platform using 'cordova platform add android'
  3. cordova build

Build will be successfull. Now go to app folder and check package.json

{
"dependencies": {
    "cordova-android": "^8.0.0"
  },
  "devDependencies": {
    "cordova-plugin-whitelist": "^1.3.4"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {}
    },
    "platforms": [
      "android"
    ]
  }
}

Next remove platforms, plugins, package.json, package-lock.json, node_modules folders

and try to perform step 2 and 3.
If build passes, then try to delete the above mentioned folders and repeat step 2 and 3.

You will see this issue.
Now check the package.json file

It just contains below json

{
  "devDependencies": {
    "cordova-plugin-whitelist": "^1.3.4"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {}
    },
    "platforms": [
      "android"
    ]
  }
}

This json is not including dependencies key, whereas build success contains the dependecies key with cordova-android set in it.

As dependencies is not in the package.json file, cordova build is failing with error
Unable to load PlatformApi from platform. Error: Cannot find module 'properties-parser'

This issue can be avoid by add cordova-android to dependencies in the package.json
or just by executing cmd line 'npm install [email protected]' will add the dependencies to package.json

@brody4hire
Copy link

The package.json file is now required for Cordova to work.

I think we should update Cordova to check for the required configuration in package.json and show a more useful error message in case it is missing.

@bandhavya
Copy link
Author

@brodybits
Yes. Cordova has to handle this

@ferrinweb
Copy link

I solved this problem by upgrading the nodejs version to the latest!
The specific reason is that the node version required by fs-extra must be greater than 10.

@newuser44
Copy link

Thanks google-- I'm here.
So I have been dealing with for half a day. Upgraded Cordova from 8 to 9.0. I have to manually add I think I'm up to 20 or more modules now.
Both adding and removing needed different modules and now building android is complaining.

Failed to instantiate ProjectBuilder builder: Error: Cannot find module 'dot-prop'
Cannot find module 'shebang-regex'
Cannot find module 'minimatch'
Cannot find module 'abbrev'

@breautek
Copy link
Contributor

Thanks google-- I'm here.
So I have been dealing with for half a day. Upgraded Cordova from 8 to 9.0. I have to manually add I think I'm up to 20 or more modules now.
Both adding and removing needed different modules and now building android is complaining.

Failed to instantiate ProjectBuilder builder: Error: Cannot find module 'dot-prop'
Cannot find module 'shebang-regex'
Cannot find module 'minimatch'
Cannot find module 'abbrev'

You shouldn't need to manually add any dependencies, but it is possible that you're using an out-dated/unsupported version of cordova-android

The latest CLI is version 10, and the latest cordova-android version is 9.1.0. I'd try first upgrading to the latest CLI and then re-adding the cordova-android platform.

If cordova platform remove android doesn't work for whatever reason, you can do the following:

rm -r plugins
rm -r platforms
rm -r node_modules
rm package-lock.json
npm install
cordova platform add android@latest

It's also recommended to use the latest available release of whatever major of Node you're using. Refer to the table below:

NodeJS Major Latest Version
10.x 10.24.1
12.x 12.22.1
14.x 14.16.1

Odd major versions of Node (e.g: 11.x, 13.x, 15.x) is not supported. They may or may not work.

There doesn't appear to be an actual issue here related to cordova-cli other than aforementioned issue with detecting what is a valid cordova project in general to provide better error feedback. There is a ticket for this discussion apache/cordova#155 therefore I'll be closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants