An app's two SwiftPM dependencies require incompatible major versions of a shared logging package; how does SwiftPM report the conflict, and how do you resolve it?
answer
- one version per package identity
- the resolver explains its chain
- a release that widens the range
- the root package has the last word
- module aliases are a different problem
basics
~20 sResolution fails with "Dependencies could not be resolved because..." and a chain naming which release needs which range of the shared package. Fix it with a dependency release that accepts the other major, an older compatible release, or a temporary root override.
solid answer
~50 sSwiftPM picks exactly one version of each package identity for the whole graph, so if one dependency needs `app-logging` 1.x and another needs 2.x, resolution fails before anything builds. The error starts "Dependencies could not be resolved because" and walks the chain: the root's requirements, which release of each dependency needs which range of the shared package, and that no newer release in range exists. First look for a release of the lagging dependency that supports the new major and update to it, possibly bumping your own requirement. Otherwise hold the other dependency back to a release still on 1.x. As a last resort, the root manifest can override the shared package with a branch or local path, which wins over the ranges below it, but then you are building a dependency against an API it never declared support for, so test it and remove the override quickly.
code
swift · 17 lines// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "ShopApp",
dependencies: [
.package(url: "https://example.com/vendor/analytics-sdk.git", from: "3.0.0"),
// Temporary: hold crash-reporter below 3.0.0, the first release built on app-logging 2.x
.package(url: "https://example.com/vendor/crash-reporter.git", from: "2.0.0"),
],
targets: [
.executableTarget(name: "ShopApp", dependencies: [
.product(name: "AnalyticsSDK", package: "analytics-sdk"),
.product(name: "CrashReporter", package: "crash-reporter"),
]),
]
)go deeper
Recall that SwiftPM chooses a single version of each package for the whole graph, so two incompatible requirements make resolution fail.
Walk through the resolver's error line by line and say which release of which dependency needs which range of the shared package.
Rank the fixes: update the lagging dependency, hold the other one back, or override at the root, and explain the risk the override carries.
Treat recurring conflicts as a dependency-hygiene signal: fewer heavy third-party graphs, regular updates, and a policy for how long a workaround may live.
## Why the graph cannot hold both versions Swift Package Manager resolves **one version of each package identity** for the entire dependency graph; there is no way to link two releases of the same package side by side. Requirements written as `from:` stop below the next major version, so when one dependency needs `app-logging` 1.4.0 ..< 2.0.0 and another needs 2.1.0 ..< 3.0.0, the intersection is empty. The SwiftPM documentation lists this as **incompatible major version requirements** and notes it "often arises when a dependency shared by many packages updates to a new major version, and it takes a long time for all of those packages to update their dependency". The same failure comes from requirements that are too strict, such as two `exact:` pins on different patch releases. ## Reading the error Resolution runs before any build, test or `swift package resolve`, and stops with an explanation. With SwiftPM 6.4, an app depending on `analytics-sdk` and `crash-reporter` reports: ```plaintext error: Dependencies could not be resolved because root depends on 'analytics-sdk' 3.0.0..<4.0.0 and root depends on 'crash-reporter' 3.0.0..<4.0.0. 'crash-reporter' is incompatible with 'analytics-sdk' because 'analytics-sdk' 3.0.0 depends on 'app-logging' 1.4.0..<2.0.0 and no versions of 'analytics-sdk' match the requirement 3.0.1..<4.0.0. 'crash-reporter' >= 3.0.0 practically depends on 'app-logging' 2.1.0..<3.0.0 because no versions of 'crash-reporter' match the requirement 3.0.1..<4.0.0 and 'crash-reporter' 3.0.0 depends on 'app-logging' 2.1.0..<3.0.0. ``` Read it as a proof: - **"root depends on"** names your own requirements, as identities in lower case. - **"3.0.0 depends on 'app-logging' 1.4.0..<2.0.0"** pins the blame on one release of one dependency. - **"no versions ... match the requirement 3.0.1..<4.0.0"** says there is no release above 3.0.0 inside your range at all, so nothing newer within it can help. When newer releases exist but conflict too, the message names each of them instead. - **"practically depends on"** means every release of that dependency inside your range needs the other major. ## Ways out, in order of preference 1. **Update the lagging dependency.** Look for a release of `analytics-sdk` whose manifest accepts `app-logging` 2.x. If it is inside your range, `swift package update analytics-sdk` finds it; if it is a new major, raise your requirement. In a local reproduction, publishing `analytics-sdk` 3.1.0 with the requirement `"1.4.0"..<"3.0.0"` let the same graph resolve, with `app-logging` at 2.1.0. 2. **Hold the other dependency back.** Lower or cap your requirement on `crash-reporter` to a release that still uses `app-logging` 1.x, with a range that ends below the first 2.x-based release. That is an app-only workaround with an owner and an end date. 3. **Ask upstream to widen its range**, and in the meantime fork the dependency, widen the requirement in the fork and depend on the fork. 4. **Override at the root.** A branch, revision or local path requirement for `app-logging` in the root manifest takes precedence over the ranges declared below it; in the same reproduction, adding either a `branch:` or a `revision:` requirement for the shared package resolved the conflicting graph. A plain range at the root does not help: it only adds one more constraint. The override compiles `analytics-sdk` against an API it never declared support for, so it needs tests and a removal date. ## What does not work - `moduleAliases` on a `.product(...)` target dependency (tools version 5.7) renames modules so that *different packages* with the same module name can coexist; it cannot place two versions of one package in the graph. - Deleting `Package.resolved` or running `swift package update` cannot help when no combination satisfies the requirements; both just reach the same error. - Adding a range requirement for the shared package to the root manifest; in the same reproduction, a root `from: "2.1.0"` only added a third constraint and the error remained. ## Preventing the next one | Practice | Why it helps | |---|---| | Libraries use `from:` ranges, never `exact:` | the graph has room to find a common version | | Libraries never ship branch or revision dependencies | a release with an unversioned dependency cannot satisfy a version requirement | | Apps update dependencies regularly | the graph does not fall several majors behind and jump all at once | | Read release notes for a shared package's new major | you know which dependents still need to move | Once resolution succeeds again, `swift package show-dependencies` prints the resolved tree, which is the quickest way to confirm which dependency now brings which version of the shared package.
- Why does a root-level branch requirement win over the ranges declared by dependencies, and why is that dangerous?SwiftPM gives the top-level package's unversioned requirements precedence for that package, so a branch, revision or local path at the root replaces whatever ranges dependencies declared. The danger is that the dependency asking for 1.x is now compiled against 2.x code it never declared support for; it may fail to build, or worse, build and behave differently. Treat it as a short-lived bridge with tests and a removal date.
- The error says no versions match 3.0.1..<4.0.0. What does that tell you?The dependency has no release at all between 3.0.1 and 4.0.0, so inside your `from: "3.0.0"` range only 3.0.0 exists, and it carries the incompatible requirement. `swift package update` therefore cannot fix this graph; you need a release outside your range, a different requirement or an upstream change. When newer releases exist but also conflict, the error names each of them instead.
- SwiftPM will link logging 1.x and 2.x side by side, one for each dependency.
- moduleAliases lets two versions of the same package live in one graph.
- Deleting Package.resolved and resolving again usually clears a version conflict.
- Adding a from: requirement on the shared package at the root forces one version.
- A root-level branch override is a safe permanent fix for a version conflict.