Install a local plugin (vs from npm)

Our project makes use of a native plugin we have created, which we store in the root of our project repo in a directory called plugin-src. Let’s say the plugin is called com.plugin.name.

We install the plugin using the following command;

ionic cordova plugin add plugin-src/com.plugin.name --save --nofetch

And all works swimmingly. This also updates package.json to include the following (abbreviate for readability);

"dependencies": {
    "com.plugin.name": "file:plugins-src/com.plugin.name",
},
"cordova": {
    "plugins": {
        "com.plugin.name": {}
    }
}

Everything works great, and we can add and remove the plugin all day long. However, if someone else pulls the repo and runs ‘npm install’ it fails, as it claims it can’t find the plugin.

What are we doing wrong? There must be a way to store the plugin local to the app surely?

To help shortcut some responses;

  • We can’t store the plugin in a public Git repo, as its proprietary
  • Likewise we can’t publish it to npm
  • After npm install fails, we can manually add the plugin using the same ionic cordova plugin add command as above
  • We’ve also tried installing with a path of ./ which adds the same to package.json, but fails in the same way

Can anyone help? We really want to have a repo where users can pull, run npm install and run ionic cordoba build and this is stopping us from being able to do so

For reference, here is our environment setup;

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.10.2
ionic (Ionic CLI) : 3.10.3

global packages:

Cordova CLI : 7.0.1 

local packages:

@ionic/app-scripts : 2.1.4
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.6.0

System:

Android SDK Tools : 25.2.3
ios-deploy        : 1.9.2 
ios-sim           : 5.0.11 
Node              : v6.9.1
npm               : 4.0.2 
OS                : macOS Sierra
Xcode             : Xcode 9.0.1 Build version 9A1004 

Any help would be really appreciated.

No experience, but might https://docs.npmjs.com/cli/link help here?

Thanks for this. Unfortunately it doesn’t look like it’s the right thing.
If I understand correctly, we could move the plugin-src directory out of
the main repo, and reference in the project using this command, but if
anything the problem of a clean pull being able to simply run npm install
would, if anything, would be compounded.

1 Like

i think you are using your local refernce,
check out this link
that’s why when you move your source to a new system it is not able to detect the reference

It is local, but also relative. And to a directory which is part of the project and therefore accurate on any machine.

Seems like exactly the kind of thing the npm docs are referring to - in fact those docs are how we got it installed in the first place.

I emailed npm support once, and they were very helpful.

A bit of an update …

package.json now seems to be working correctly with the following value;

“dependencies”: {
com.plugin.name”: “file:./plugins-src/com.plugin.name”,
},
“cordova”: {
“plugins”: {
com.plugin.name”: {}
}
}

So on a clean pull of the repo I can run ‘npm install’ and the module appears to install correctly.

However, when I then run ionic cordova build ios I get an error.

Failed to restore plugin “com.plugin.name” from config.xml. You might need to try adding it again. Error: Failed to fetch plugin com.plugin.name@file:./plugins-src/com.plugin.name via registry.

Looking in config.xml, I noticed that the value is set as follows;

<plugin name="com.plugin.name" spec="file:./plugins-src/com.plugin.name" />

which seems correct. However, I thought I’d try modifying the path to see if it is the file:./ syntax which Cordova baulks at, whereas npm accepts. So I change config.xml to include the following;

<plugin name="com.plugin.name" spec="./plugins-src/com.plugin.name" />

However, when I run ‘ionic cordova build ios’ again, something in the build sequence appears to overwrite this value, reverting it back to

<plugin name="com.plugin.name" spec="file:./plugins-src/com.plugin.name" />

So it appears the problem now lies somewhere in the Cordova toolchain, and its parsing/construction of config.xml rather than in npm.

Can anyone help? Feels like this should be quite straightforward, but its been a block for us for over a week now.

Did you finally add plugin from repo? If yes tell me how you did it :).

Did you manage to sort it?

Did you managed? I’ve encountered the same issue