npm install fails with "ERESOLVE unable to resolve dependency tree" for @cdktf/provider packages
Fixes the npm ERESOLVE peer-dependency conflict when installing CDKTF provider packages built against a different cdktf version (e.g. provider-docker 3.0.11 wanting cdktf ^0.13.0 while the project has 0.14.0-pre.5). Covers aligning versions, --legacy-peer-deps, and regenerating bindings with cdktf get. Use when npm install of a @cdktf/provider-* package fails on peer deps. Not for cdktf synth or deploy errors.
TL;DR
Align the provider package version with your cdktf version (check the provider's peer dependency range), or install with npm install --legacy-peer-deps as a short-term workaround. Long term, regenerate bindings with cdktf get so the provider matches your cdktf.
The error
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! Found: cdktf@0.14.0-pre.5
npm ERR! Could not resolve dependency:
npm ERR! peer cdktf@"^0.13.0" from @cdktf/provider-docker@3.0.11Fix it
- Check which cdktf version your project uses (
npm ls cdktf) and which range the provider wants (the error names it, e.g.^0.13.0). - Preferred: install a provider release whose peer range includes your cdktf version, e.g.
npm install @cdktf/provider-docker@[matching]. - Alternative: generate the bindings yourself with
cdktf get/cdktf provider addinstead of installing a prebuilt provider package; generated bindings track your cdktf version. - Short-term workaround only:
npm install --legacy-peer-deps(accepts a possibly broken resolution; verifycdktf synthstill works after). - Re-run
cdktf synthto confirm the installed provider actually works.
Expected result: npm install completes and synth runs against the provider.
When to use this
npm install @cdktf/provider-*fails with ERESOLVE peer dependency errors- You are on a cdktf pre-release or a new minor and the prebuilt provider lags behind
When NOT to use this
- The install succeeds but synth fails (that is a code/schema problem)
- You use Python/Go (use pip/Go modules; the same version-skew idea applies to cdktf-cdktf-provider-* pins)
Root cause
Prebuilt @cdktf/provider-* packages declare a peer dependency on a specific cdktf range. When your project moves to a newer (or pre-release) cdktf first, npm refuses to resolve the tree because no single cdktf satisfies both. The provider bindings are generated against a cdktf version, so a stale prebuilt package is genuinely built for the older API.
Edge cases
--forcealso bypasses the check but is harsher than--legacy-peer-deps; prefer the latter.- After upgrading cdktf, re-run
cdktf getto regenerate bindings even if npm is happy.