Search code examples
cordovaionic-frameworkionic3ionic4cordova-plugins

ionic cordova local plugin error with new M1 macs


We have a some local plugins which were added using ionic cordova plugin add ./cordova-plugin-name

When building on intel macs they work fine, but in the new M1 mac with Big Sur I get the below error when building the project

Discovered saved plugin "cordova-plugin-ionic-keyboard". Adding it to the project
Installing "cordova-plugin-ionic-keyboard" for ios
Adding cordova-plugin-ionic-keyboard to package.json
Discovered saved plugin "cordova-plugin-iovation". Adding it to the project
Failed to restore plugin "cordova-plugin-iovation" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin file:scripts/plugin/cordova-plugin-iovation via registry. Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR!
Cannot read property 'match' of undefined
npm ERR!
npm ERR!
Discovered saved plugin "cordova-plugin-advanced-http". Adding it to the project
Failed to restore plugin "cordova-plugin-advanced-http" from config.xml. You might need to try adding it again. Error: Failed to fetch plugin file:scripts/plugin/cordova-plugin-advanced-http via re gistry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: npm: Command failed with exit code 1 Error output:
npm ERR!
Cannot read property 'match' of undefined
A complete log of this run can be found in: /Users/xx/.npm/_logs/2021-01-21T12_29_50_477Z-debug.log
npm ERR!
npm ERR!
Discovered saved plugin "call-number". Adding it to the project
Installing "mx.ferreyra.callnumber" for ios
Adding mx.ferreyra.callnumber to package.json
Discovered saved plugin "cordova-plugin-app-version". Adding it
Installing "cordova-plugin-app-version" for ios

Is this a known issue and how can I fix it?


Solution

  • It looks like the CLI doesn't understand that these are local plugins and therefore it tries to download them from the registry. This is most likely an npm problem. Something doesn't play nice with cordova and npm 7. I suggest you run node v15.6.0 (latest non lts).

    This version normally comes bundled with a newer npm (v7), however for this to work (until cordova sorts their stuff out), you have to downgrade npm to 6.14.11

    I have done this with (the use of sudo or not will depend on your environment setup):

    sudo npm i -g npm
    

    Or you can specify a version with:

    sudo npm i -g npm@version
    

    Source for the above solution: https://github.com/apache/cordova-cli/issues/541

    Other than that, I just had to fight for a few hour to get stuff building on my M1...

    Some hints that will probably help you out tremendously:

    • Cocoapods needs to be installed in a rosetta mode terminal. You will most likely need to install the ffi gem in that same terminal before installing cocoapods and running pod install inside the ios platform folder. The native ffi gem that is there by default doesn't seem to work with cocoapods.
    • You will have to exclude arm64 and x86_64 architecture emulators from being built automatically in XCode. If you don't you will get symbols missing errors on build.

    UPDATE: It looks like cordova has now fixed this issue by sorting out their dependencies. Uninstalling and reinstalling cordova should get all the packages needed for it to work with the latest stable npm