cordova-cli icon indicating copy to clipboard operation
cordova-cli copied to clipboard

Plugins are not restored from package.json but only from config.xml

Open aidanas opened this issue 5 years ago • 3 comments
trafficstars

Bug Report

Problem

Plugins are not restored from package.json. They are only restored if listed in config.xml but since Cordova 9 plugins are to be managed with package.json. Steps to recreate:

  1. Create new app: cordova create testPluginRestore com.example.testpluginrestore TestPluginRestore
  2. Add platform: cordova platform add android
  3. Add plugin: cordova plugin add cordova-plugin-geolocation
  4. Check plugin added ok? cordova plugin ls Lists plugin OK. Also entry in package.json is present.
  5. Clean plugins and pltfroms rm -rf platforms/ plugins/ node_modules/
  6. Prepare android cordova prepare android
  7. Check plugins restored cordova plugin ls

What is expected to happen?

  • cordova-plugin-geolocation plugin to be restored and listed in the list

What does actually happen?

  • cordova-plugin-geolocation is not restored.

Information

The same behaviour was tested with other plugins cordova-plugin-camera, cordova-plugin-firebase-dynamiclinks, and others with the same outcome.

Command or Code

Environment, Platform, Device

  • Mac OS

Version information

  • Cordova CLI 9.0.0

Checklist

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

aidanas avatar Jun 21 '20 09:06 aidanas

@aidanas Can you please test with cordova@nightly and confirm if this is still an issue?

When I tested with nightly and it appears that plugins are being restored correctly.

rm -rf package-lock.json node_modules platforms plugins

$ cordova prepare
Warning: using prerelease version 10.0.0-nightly.2020.6.24.7b8e8678 ([email protected])
Discovered platform "android". Adding it to the project
Using cordova-fetch for [email protected]
Adding android project...
Creating Cordova project for the Android platform:
	Path: platforms/android
	Package: com.test.foobar
	Name: foobar
	Activity: MainActivity
	Android target: android-28
Subproject Path: CordovaLib
Subproject Path: app
Android project created with [email protected]
Discovered plugin "cordova-plugin-whitelist". Adding it to the project
Installing "cordova-plugin-whitelist" for android
Discovered plugin "cordova-plugin-geolocation". Adding it to the project
Installing "cordova-plugin-geolocation" for android
Installing "cordova-plugin-compat" for android
Plugin doesn't support this project's cordova-android version. cordova-android: 8.0.0, failed version requirement:
      <6.3.0
Skipping 'cordova-plugin-compat' for android

$ cordova plugin ls
Warning: using prerelease version 10.0.0-nightly.2020.6.24.7b8e8678 ([email protected])
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-whitelist 1.3.4 "Whitelist"

The issue you are reporting might exist in 9.x but not in the upcoming 10.x release which is being prepared.

You can test with nightly by updating your global install:

npm uninstall -g cordova
npm install -g cordova@nightly

You might also be able to use npx command instead of upgrading your global install of Cordova.

In your Cordova project directory, you could try this:

rm -rf package-lock.json node_modules platforms plugins
npx cordova@nightly prepare

Please remember that nightly is not production ready as it has not been voted on for release.

erisu avatar Jun 24 '20 05:06 erisu

@erisu, thanks for the heads up! I can confirm that using Cordova 10 nightly build (10.0.0-nightly.2020.6.29.7b8e8678) it seems to restore plugins OK.

I get however Cannot find module 'properties-parser' error but that could be just broken nightly build or some other, potentially unrelated, issue on my end.

Aidanass-MBP:testPluginRestore aidanas$ npx cordova prepare android
Warning: using prerelease version 10.0.0-nightly.2020.6.29.7b8e8678 ([email protected])
Discovered platform "android". Adding it to the project
Using cordova-fetch for cordova-android@^8.1.0
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms/android
        Package: com.example.testpluginrestore
        Name: TestPluginRestore
        Activity: MainActivity
        Android target: android-28
Subproject Path: CordovaLib
Subproject Path: app
Android project created with [email protected]
Discovered plugin "cordova-plugin-whitelist". Adding it to the project
Installing "cordova-plugin-whitelist" for android
Discovered plugin "cordova-plugin-geolocation". Adding it to the project
Installing "cordova-plugin-geolocation" for android
Cannot find module 'properties-parser'
Aidanass-MBP:testPluginRestore aidanas$ cordova plugin ls
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-whitelist 1.3.4 "Whitelist"

Any ETA on Cordova 10 release dates?

aidanas avatar Jun 29 '20 07:06 aidanas

I have a lot of these issues also. Remove the platform Android before your step 5 where you remove those 3 directories, and then add platform again. Cordova prepare doesn't fetch npm modules and plugins, just cordova platform add.

In short, try this sequence

cordova platform rm android
rm -rf platforms/ plugins/ node_modules/
cordova platform add android

It should work on the latest version of cordova cli

jfoclpf avatar Mar 30 '21 13:03 jfoclpf