pub get stops because your package depends on its own name
pub get failedShort 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.
Fix it fast
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 above2Match what you see, then jump to its fix
- 1
The 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
The error points into dev_dependencies or dependency_overrides, not dependenciesThe same name is repeated in dev_dependencies or dependency_overridesFix - 3
The error names pubspec_overrides.yamlpubspec_overrides.yaml repeats the nameFix
- 1
What does the error look like?
pub get failedA 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.yaml2Fix
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.03Verify
pub get runs to the end without the error.
flutter pub getConfirmed by dart.dev
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.yaml2Fix
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 getConfirmed by github.com
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.yaml2Fix
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_package3Verify
Run pub get again.
flutter pub getConfirmed by github.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
flutter pub get fails and no packages are downloaded
Got socket error trying to find package
Run pub get in a terminal and read the first error.
4 causes, each with a fixMobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fix