Search code examples
cordovapluginscordova-pluginscordova-4

Error installing cordova-plugin-inappbrowser: "Error: Expected "*/" or [^*] but "*" found"


When running

cordova plugin add cordova-plugin-inappbrowser

I always get the following errors:

Fetching plugin "cordova-plugin-inappbrowser@~1.2.0" via npm
Installing "cordova-plugin-inappbrowser" for ios
Failed to install 'cordova-plugin-inappbrowser':undefined
Error: Expected "*/" or [^*] but "*" found.

Many of the infos I found are far outdated. I have:

[email protected]
[email protected]

Solution

  • Here are a few different ways you can go about fixing your issue:



    1. Check if everything is generating as it should and clean your project.


    Sometimes by logging things and looking at output package you can find that plugin installation is not always reliable. In some cases a couple of plugins might fail to install properly (where you see a "not defined" messages and possibly your undefined message in your logs). Usually removing and (re)adding the failing plugin can fix this issue. Another thing to try is cleaning the project before doing a build - both iOS and Android have a cleanup script available in either ./platforms/ios/cordova/clean and ./platforms/android/cordova/clean respectively which can help sometimes when run between builds.

    You can get these bad/incomplete installs sometimes if you have a bad wifi connection. You can test this by checking you the folders thenselves and the plugins/fetch.json,plugins/ios.json and plugins/android.json files.

    Your plugins/fetch.json should look like this:

        "cordova-plugin-inappbrowser": {
        "source": {
            "type": "registry",
            "id": "cordova-plugin-inappbrowser@~1.3.0" //or whatever version
        },
        "is_top_level": true,
        "variables": {}
    },
    

    When you run cordova build or cordova prepare it should autogenorate a .json for each platform you project has so if you have android and ios it sould create a android.json & ios.json and that should look like this:

    "installed_plugins": {
    "cordova-plugin-inappbrowser": {
                "PACKAGE_NAME": "com.example.hello"
            },
    

    here try removing the projects build then build it again

     rm -rf platforms/ios/build && cordova build ios
    

    Now test your project, if no luck try some of the following steps.



    2. Remove and (re)add your projects platforms and plugins folders.


    in base of your apps folder run

        rm -rf plugins/ && rm -rf platforms/
        cordova plugin add cordova-plugin-inappbrowser
        cordova platform add ios
        cordova run ios
    

    Now test your project if not try steps 3 & 4


    3. Test if running cordova plugin add cordova-plugin-inappbrowser will work correctly when in a new project


    Try running:

         cordova create hello com.example.hello "HelloWorld"
         cd hello
         cordova plugin add cordova-plugin-inappbrowser
         cordova platform add ios
         cordova build
    

    If it installed into the new project correctly go into the plugins/ folder then drag and drop the cordova-plugin-inappbrowser plugin folder into your current projects plugins/ folder then test your project again, if your still having an issue double check the make sure the fetch.json or ios.json / android.json files are genorating correctly and they look something like what's in #1.

    Also assuming the plugin works in your new app and the new app is using the same app name and package name (when you ran cordova create hello com.example.hello "HelloWorld") you can also simply replace your current www/ in the new project and run it and you shouldn't run into any problems.

    4. Similar to step #3, download the plugin not using the cli then add it to your project


    Try downloading the .zip file for the plugin here https://github.com/apache/cordova-plugin-inappbrowser and add it to your plugins folder then test your project

    5. Update your project and cli


    Try to be on the current 4.1.0 for ios so in your project folder try running

    rm -rf plugins/ && rm -rf platforms/ && cordova platform add ios
    cordova platforms update [email protected]
    cordova plugin add cordova-plugin-inappbrowser
    cordova run ios --device
    

    You can also change your projects version (cordova-ios or cordova-android) versions by specifying in your platforms/platforms.json

    e.i.

    {
        "ios": "4.1.0"
    "android": [version number]
    }
    

    Although it is the current version and will hopefully be issue free I have ran into a plugin issue with this where I am currently using a lower version, so if you are still having issues try again with with version @4.0.0 or @3.6.3 you can do so with some of the other useful commands I have provided under #6



    6.Make sure you have the right permissions


    There is also a chance you could be having a cordova permissions issue so try checking or changing the following locations

    run:

    whoami 
    

    to find your user name, use that name here:

    sudo chown -R [add your username here] /usr/local/lib/node_modules/cordova
    

    ie

    sudo chown -R bobsagit /usr/local/lib/node_modules/cordova
    
    
    sudo chmod -R 777 /Users/[bobsagit]/.config/
    sudo chmod -R 777 ./platforms/ios/
    

    and your project folder, assuming its on the desktop and named ExampleProject

    sudo chmod -R 777 ~/Desktop/ExampleProject/platforms/ios
    




    Other Useful commands

    in your apps root folder you can try some of the following
    to see the plugins in your current project

    cordova plugins list
    

    to check what platforms version in you current project run

    cordova platform list
    

    or

     cordova platform version
    

    It will give you the following output

    Installed platforms: android 3.5.1, ios 3.5.0
    Available platforms: amazon-fireos, blackberry10, browser, firefoxos
    

    check the current platform version of a cordova app

    cordova platform version ios
    

    to update your existing version

    cordova platform update ios
    

    to change projects version first install globally with the version you'd like then add it to your project

    sudo npm install -g [email protected]
    cordova platform add [email protected] 
    

    or to update to a specify a specific version

    cordova platform update [email protected]
    

    to see the currently running cordova version on your machine run

    cordova --version
    

    for more detail run

    npm info cordova
    

    Addition notes:
    When you add cordova plugins they are plugins meant for the device and not the browser so make sure you testing on a device by appending --device to your run command like so cordova run ios --device

    The old cli you would add plugin with a . syntax ie org.apache.cordova.inappbrowser now you don't, so make sure you are using -'s like you where doing cordova-plugin-inappbrowser

    UPDATE: I just read your comment where you said it it works in a different project. I don't know much about http://www.macincloud.com/ but it looks like your problem is an issue from the initial install of the plugin so try cleaning it or remove and adding it back like in step 1 and 2