How can I get cordova to use yarn js instead of npm for adding plugins
Asked Answered
L

2

15

Question updated

I currently add plugins to my cordova project using the command cordova plugin add x. I believe this uses npm in the background.

Does anyone have any idea how I can switch npm out for yarn js (within cordova, I want cordova to use yarn instead of npm), since it would make such a massive difference in terms of caching (other than updating the cordova cli myself).

Conclusion

Dec 2016

It seems that installing yarn means that yarn takes over from npm as the default package manager, and thus things are speeded up by default and that no tinkering with Cordova is required.

Sep 2017

It seems that I was mistaken, apparently, Cordova is hardcoded to use npm, https://issues.apache.org/jira/browse/CB-12242. I will re-open this issue to request Apache to make this an option.

Lectureship answered 13/12, 2016 at 16:2 Comment(2)
Have you resolved this issue?Cetology
@JinyoungKim - Yes, just install cordova with yarn, and it should work. I do suggest installing the system version of yarn, not the npm version.Lectureship
L
6

It seems the short answer is no - it is not currently possible, but I am going to request an update from Apache: https://issues.apache.org/jira/browse/CB-12242

Lectureship answered 7/9, 2017 at 19:0 Comment(0)
H
0

I'm successfully using Yarn (v1) together with a cordova project. While I'm quite upset that the cordova devs dictate which package manager must be used, there's a trick to make it work: Do not use cordova to add/remove/change plugins and make sure it has no reason to ever try to do so automatically:

  • Add/remove/manage all cordova plugins manually in package.json, including the cordova.plugins section of that file.
  • Add/remove/manager all platforms manually in package.json, including the cordova.platforms section.
  • The plugins should also be properly listed in config.xml, using the exact same version spec as in package.json.

Example package.json:

{
    ...
    "dependencies": {
        ...
        "cordova-plugin-file": "~8.0.1"
    },
    "cordova": {
        ...
        "plugins": {
            ...
            "cordova-plugin-file": {
            },
        }
    }
}

Example config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget ...>
    ...
    <plugin name="cordova-plugin-file" spec="~8.0.1"/>
    ...
</widget>

If everything is correct, then the cordova prepare command will have no reason to attempt to install anything. In fact, whenever it does, it means something was no right. This can usually be detected by npm wrecking the yarn.lock file.

Harri answered 6/8, 2024 at 12:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.