skip to Main Content

I’m currently stuck on a problem related to my Ionic project.

I have an Ionic project on GitHub which i’ve been working on in the past few weeks, i have a few Cordova plugins as part of the project.

When downloading the project from GitHub, i can run the app using Ionic Serve without a problem. However, when trying to setup the project for xCode to run on local device(s), i run into a multitude of errors

Some include:

  1. When running ionic ‘cordova platform add ios’ the following error appears

Error: Could not install from "ios" as it does not contain a package.json file.

  1. When trying to run ‘ionic cordova run ios -l –external’

Error: Error: terminating with uncaught exception of type NSException

I have not yet tried to transfer my code into a new Ionic project, as i wish to see if my problem can be solved without that hassle.

View project code here: https://github.com/designsheikh/bitsandbobs.git

2

Answers


  1. Chosen as BEST ANSWER

    @Reqven

    Thank you for your support! - i was sure that i had done this step while trying to fix the issue. It is such an absurd problem, it seems that there is a new project architecture as you mentioned which needs to be followed. I followed your steps with also one minor additional step as im working on the iIOS platform:

    1. Delete iOS folder
    2. cordova platform add ios
    3. cordova prepare ios
    4. ionic build

    If step 2 throws an error causing the version not to be found or integrated into the project run - include '@latest' this also solved my problem


  2. I figured it out. You have the exact same issue I’ve had with the android platform.
    As I pointed it out in the comments, it is indeed caused by a "corrupted" project architecture.

    How it happened

    Initially, I had an issue with the cordova generated resources, somehow not being copied into the android platform directory. I tried plenty of things with the cordova-res CLI, including using the --copy and the --ios-project flags to force the copy to happen in the directory of my choice.

    I couldn’t manage to fix my issue, and then decided to rollback all my changes and start over on a clean project to try something else. Since then, I was not able to add the android platform anymore. Every single time, the following error was being thrown :

    Error: Could not install from "android" as it does not contain a package.json file.
    

    Explanation

    With all my testing, I noticed that when using cordova to add the platform or copy the resources over, somehow, it had created the android platform in the wrong directory, at the root of my project instead of in the platforms folder. And that’s where the issue comes from.

    I can’t explain it, but you will encounter this error every single time if you try to add a platform with cordova while having a folder with this platform name at the root of your project. I have no idea why this would prevent a platform from being added to the project, maybe this folder is used as a temp folder by the CLI.

    Solution

    The fix is to simply remove any ios or android directory at the root of your project.
    The error will go away and you will be able to add the platform again.


    @CodingJunkie

    Regarding the Github repository you provided in your post, you will likely run into another error while trying to add the ios platform if you use cordova@>=9.0.0.

    Using "requireCordovaModule" to load non-cordova module "xcode" is not supported.  
    Instead, add this module to your dependencies and use regular "require" to load it.
    

    Check this issue#1033 for a workaround. However, it’s not recommended to directly edit the plugin source code, you might want to look for another cordova Firebase plugin.

    I also noticed you kinda mixed up cordova and capacitor in your project.
    Make sure to use one or the other to avoid potential errors.

    Hope this helped !

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search