Search code examples
yarnpkgjspdf

How can I install the latest version of jsPDF using yarn?


The current stable release is 1.5.3 of jsPDF but it's nearly 2 years old.

The master branch is already on 2.1.1. The fix I need is in a patch just after 1.5.3.

How can I use yarn to install this version?

Currently my package.json file looks like this:

"dependencies": {
    "jspdf: "^1.5.3",
    "jspdf-autotable": "^3.3.2"

}

Solution

  • You can specify the version using a git url. For GitHub repos, you can use the short version user/repo#<commit-ish>, where commit-ish is a commit hash, branch, or tag.

    Using the latest commit on the master branch as an example:

    "dependencies": {
        "jspdf: "MrRio/jsPDF#2c5e6c7",
        "jspdf-autotable": "^3.3.2"
    
    }
    

    This will work with both Yarn and NPM.

    NPM docs: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies