Maaz Zindani

Loading the index…

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

The analyzer says an imported package is not a dependency of your package

ErrorThe imported package 'path' isn't a dependency of the importing package

Short 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.

  • Applies to Dart 3.9, Flutter 3.35
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.yaml
  2. 2Match what you see, then jump to its fix

    1. 1The warning is on an import inside lib/ or bin/The package is used in lib but missing from dependenciesFix
    2. 2The warning is in test/, integration_test/ or a script outside libThe package is only used by tests or toolingFix
    3. 3pubspec.yaml lists the package but the editor still shows the warningA dependency was added by hand and the file was not saved or fetchedFix

What does the error look like?

  • The imported package 'path' isn't a dependency of the importing package
  • depend_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/ | head

2Fix

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 path

3Verify

Run the analyzer; the warning for that import is gone.

dart analyze

Confirmed by dart.dev

Did this fix it?

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/null

2Fix

If only test code imports it, add it as a dev dependency.

dart pub add dev:path

3Verify

Fetch packages again and re-run the analyzer.

dart pub get
dart analyze

Confirmed by dart.dev

Did this fix it?

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 get

2Fix

Run pub get after every manual pubspec change and let the IDE reload the analysis.

dart pub get

3Verify

Restart the analysis server in the IDE, or run the analyzer.

dart analyze

Confirmed by dart.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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