dart-resolve-package-conflicts
Original:🇺🇸 English
Translated
Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.
19installs
Sourcedart-lang/skills
Added on
NPX Install
npx skill4agent add dart-lang/skills dart-resolve-package-conflictsTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Managing Dart Dependencies
Contents
- Core Concepts
- Version Constraints
- Workflow: Auditing Dependencies
- Workflow: Upgrading Dependencies
- Workflow: Resolving Version Conflicts
- Examples
Core Concepts
Dart enforces a strict single-version rule for dependencies: a project and all its transitive dependencies must resolve to a single, shared version of any given package. This prevents runtime type mismatches but introduces the risk of "version lock."
To mitigate version lock, Dart relies on version constraints rather than pinned versions in the . The file maintains the exact resolved versions for reproducible builds.
pubspec.yamlpubspec.lockUnderstand the output columns of :
dart pub outdated- Current: The version currently recorded in .
pubspec.lock - Upgradable: The latest version allowed by the constraints in .
pubspec.yamlresolves to this.dart pub upgrade - Resolvable: The absolute latest version that can be resolved when factoring in all other dependencies in the project.
- Latest: The latest published version of the package (excluding prereleases).
Version Constraints
- Use Caret Syntax: Always use caret syntax (e.g., ) for dependencies in
^1.2.3. This allowspubspec.yamlto select newer, non-breaking versions (up to, but not including, the next major version) during resolution.pub - Tighten Dev Dependencies: Set the lower bound of to the exact version currently used. This reduces resolution complexity and prevents older, incompatible dev tools from being selected.
dev_dependencies - Enforce Lockfiles in CI: Use in CI/CD pipelines to ensure the exact versions tested locally are used in production.
dart pub get --enforce-lockfile
Workflow: Auditing Dependencies
Run this workflow periodically to identify stale packages that may impact stability or performance.
Task Progress:
- Run .
dart pub outdated - Review the Upgradable column to identify packages that can be updated without modifying .
pubspec.yaml - Review the Resolvable column to identify packages that require constraint modifications in to update.
pubspec.yaml - Identify any packages marked as retracted or discontinued.
Workflow: Upgrading Dependencies
Use conditional logic based on the audit results to upgrade dependencies.
Task Progress:
- If updating to "Upgradable" versions:
- Run .
dart pub upgrade - Run to automatically update the lower bounds in
dart pub upgrade --tightento match the newly resolved versions.pubspec.yaml
- Run
- If updating to "Resolvable" versions (Major updates):
- Manually edit to bump the version constraint to match the "Resolvable" column (e.g., change
pubspec.yamlto^0.11.0).^0.12.1 - Run to resolve the new constraints and update
dart pub upgrade.pubspec.lock
- Manually edit
- Feedback Loop:
- Run -> review errors -> fix breaking API changes.
dart analyze - Run -> review failures -> fix regressions.
dart test
- Run
Workflow: Resolving Version Conflicts
When cannot find a set of concrete versions that satisfy all constraints, or when dealing with a retracted package version, manipulate the lockfile surgically.
pubNEVER delete the entire file and run . This causes uncontrolled upgrades across the entire dependency graph.
pubspec.lockdart pub getTask Progress:
- Open .
pubspec.lock - Locate the specific YAML block for the conflicting or retracted package.
- Delete ONLY that package's entry from the lockfile.
- Run to fetch the newest compatible, non-retracted version for that specific package.
dart pub get - Feedback Loop:
- Run -> verify the dependency graph resolves correctly.
dart pub deps - If resolution fails, identify the transitive dependency causing the lock, update its constraint in , and retry.
pubspec.yaml
- Run
Examples
Tightening Constraints
When shows a package is resolvable to a higher minor/patch version, use the flag to update the automatically.
dart pub outdated--tightenpubspec.yamlInput ():
pubspec.yamlyaml
dependencies:
http: ^0.13.0Command:
bash
dart pub upgrade --tighten httpOutput ():
pubspec.yamlyaml
dependencies:
http: ^0.13.5Surgical Lockfile Removal
If is retracted or locked in a conflict, remove only its block from .
package_apubspec.lockBefore ():
pubspec.lockyaml
packages:
package_a:
dependency: "direct main"
description:
name: package_a
url: "https://pub.dev"
source: hosted
version: "1.0.0" # Retracted version
package_b:
dependency: "direct main"
# ...Action: Delete the block entirely. Leave untouched. Run .
package_apackage_bdart pub get