apache / cordova-cli

Apache Cordova CLI
Apache License 2.0
940 stars 339 forks source link

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

Open aidanas opened 4 years ago

aidanas commented 4 years ago

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?

What does actually happen?

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

Version information

Checklist

erisu commented 4 years ago

@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 (cordova-lib@10.0.0-nightly.2020.6.24.909e7c72)
Discovered platform "android". Adding it to the project
Using cordova-fetch for cordova-android@8.0.0
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 cordova-android@8.0.0
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 (cordova-lib@10.0.0-nightly.2020.6.24.909e7c72)
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.

aidanas commented 4 years ago

@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 (cordova-lib@10.0.0-nightly.2020.6.29.1339ed51)
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 cordova-android@8.1.0
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?

jfoclpf commented 3 years ago

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