Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

pub get stops because your package depends on its own name

Errorpub get failed

Short answer

pub compares the name field of your pubspec.yaml with every key under dependencies, dev_dependencies and dependency_overrides, in pubspec.yaml and in pubspec_overrides.yaml. If one key is identical to your own package name, pub stops with this error. Rename your package, or remove the entry that repeats it.

  • Applies to Dart 3.x, Flutter 3.x, pub
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print your package name, then search every pubspec in the project for that same word as a dependency key. The error message points at the line, so also read the file name it prints.

    grep -n "^name:" pubspec.yaml
    grep -n "grid" pubspec.yaml pubspec_overrides.yaml 2>/dev/null   # replace grid with the name printed above
  2. 2Match what you see, then jump to its fix

    1. 1The line the error points at sits under dependencies: and its key is the same text as name: at the top of the fileThe project name equals a package you added under dependenciesFix
    2. 2The error points into dev_dependencies or dependency_overrides, not dependenciesThe same name is repeated in dev_dependencies or dependency_overridesFix
    3. 3The error names pubspec_overrides.yamlpubspec_overrides.yaml repeats the nameFix

What does the error look like?

  • pub get failed
  • A package may not list itself as a dependency.

Cause 1 of 3

The project name equals a package you added under dependencies

1Check

This happens when a project is created with a name such as the package it is meant to use (for example an app called after a grid or chart package), then that package is added. The comparison is exact text, case included.

sed -n '1,25p' pubspec.yaml

2Fix

Change name: to something unique (lowercase words joined by underscores, a valid Dart identifier). Imports written as package:<old_name>/... in your own code must then use the new name.

# pubspec.yaml
name: my_grid_app
dependencies:
  grid: ^1.0.0

3Verify

pub get runs to the end without the error.

flutter pub get

Confirmed by dart.dev

Did this fix it?

Cause 2 of 3

The same name is repeated in dev_dependencies or dependency_overrides

1Check

pub runs the same self-check on all three sections, so a leftover override or a test helper with your own package name stops pub get as well.

sed -n '/^dev_dependencies:/,$p' pubspec.yaml

2Fix

Delete the entry whose key equals your own name. If you meant a different package, give your project a different name instead.

# remove the line under dev_dependencies or dependency_overrides
# that repeats the value of name:

3Verify

Run pub get again.

dart pub get

Confirmed by github.com

Did this fix it?

Cause 3 of 3

pubspec_overrides.yaml repeats the name

1Check

pub also reads pubspec_overrides.yaml, a file next to pubspec.yaml that holds dependency_overrides, and applies the same check to it.

cat pubspec_overrides.yaml

2Fix

Remove the override whose key is your own package name, or rename the package so it no longer matches.

# pubspec_overrides.yaml
dependency_overrides:
  some_other_package:
    path: ../some_other_package

3Verify

Run pub get again.

flutter pub get

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Name a new project after your product, not after the package you plan to use.
  • After copying a pubspec from another project, change name: before the first pub get.
  • Read the file name in the pub error: it can be pubspec_overrides.yaml, not pubspec.yaml.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.