[Fixed] ERROR: Dependency @types/html2canvas must be explicitly allowed using the "allowedNonPeerDependencies" option

Issue

I have installed the html2canvas in my angular library project and, when I compile in production mode (running the ng build --prod command), I’m receiving the following error:

ERROR: Dependency @types/html2canvas must be explicitly allowed using
the "allowedNonPeerDependencies" option.

How can I solve it?

Solution

You can add the library to your peerDependencies in package.json. I strongly recommend using the peerDependencies strategy since exposes explicitly to others that your library depended on other libraries:

{
    ...
    "scripts": {...},
    "peerDependencies": {
        ...
        "@types/html2canvas": "0.0.36",
        ...
    },
}

Or you can use the option on your ng-package.json:

{
    ...
    "lib": {
        "entryFile": "src/public-api.ts"
    },
    "allowedNonPeerDependencies": [
        "@type/html2canvas"
    ]
    ...
}

Leave a Reply

(*) Required, Your email will not be published