The analyzer says an imported package is not a dependency of your package
The imported package 'path' isn't a dependency of the importing packageShort answer
The lint depend_on_referenced_packages fires when your code imports a package that your own pubspec.yaml does not list. Having it only through another package does not count. Add it yourself: under dependencies if lib or bin imports it, under dev_dependencies if only tests or tools do. Then run pub get.
Fix it fast
1Find out which cause you have
Check whether the package is in your own pubspec.yaml. Seeing it in pubspec.lock does not count, because that file also lists packages pulled in by others.
grep -n "path" pubspec.yaml2Match what you see, then jump to its fix
- 1
The warning is on an import inside lib/ or bin/The package is used in lib but missing from dependenciesFix - 2
The warning is in test/, integration_test/ or a script outside libThe package is only used by tests or toolingFix - 3
pubspec.yaml lists the package but the editor still shows the warningA dependency was added by hand and the file was not saved or fetchedFix
- 1
What does the error look like?
The imported package 'path' isn't a dependency of the importing packagedepend_on_referenced_packages
Cause 1 of 3
The package is used in lib but missing from dependencies
1Check
The Dart linter documentation says that when you import a package you must add a dependency on it. The code works today only because another package happens to bring it in.
grep -rn "import 'package:path/" lib/ | head2Fix
Add it with the pub tool. It edits pubspec.yaml and resolves versions for you.
dart pub add path
# in a Flutter app
flutter pub add path3Verify
Run the analyzer; the warning for that import is gone.
dart analyzeConfirmed by dart.dev
Cause 2 of 3
The package is only used by tests or tooling
1Check
Dart's dependency guide puts packages needed for development work such as tests under dev_dependencies, and says anything imported from lib or bin must be a regular dependency.
grep -rln "package:path/" lib/ bin/ test/ 2>/dev/null2Fix
If only test code imports it, add it as a dev dependency.
dart pub add dev:path3Verify
Fetch packages again and re-run the analyzer.
dart pub get
dart analyzeConfirmed by dart.dev
Cause 3 of 3
A dependency was added by hand and the file was not saved or fetched
1Check
Adding a dependency with pub add is described as equal to editing pubspec.yaml and then running pub get. If you edited by hand, the second step may be missing.
dart pub get2Fix
Run pub get after every manual pubspec change and let the IDE reload the analysis.
dart pub get3Verify
Restart the analysis server in the IDE, or run the analyzer.
dart analyzeConfirmed by dart.dev
How do I stop it coming back?
- Add packages with pub add instead of copying names from other projects.
- Keep depend_on_referenced_packages enabled in analysis_options.yaml so it warns before a release.
- Never rely on a package you did not list; an update of the other package can remove it.
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
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 fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix