Relative import path reaches into a lib directory

ID

dart.portability.avoid_relative_lib_imports

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Portability

Language

Dart

Description

Reports an import or export whose URI is a relative path that descends into a lib directory, such as '../lib/shared.dart' or '../../other_package/lib/api.dart'.

Rationale

Everything under lib is addressable as a package: URI, and that is the identity Dart uses for it. Reaching the same file by walking the filesystem gives it a second identity, so the analyzer treats it as a different library: instance checks against the same class fail, top-level and static state exists twice, and private members no longer match. When the path crosses into another package’s lib, it also bypasses the dependency declared in pubspec.yaml entirely, so the import resolves on the developer’s machine and fails wherever the packages are laid out differently.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Relative import path reaches into a lib directory
import '../lib/shared.dart';

Remediation

Use the package: URI for the target - package:other_package/api.dart - and declare the package in pubspec.yaml (as a dependency, or as a path dependency for a sibling package inside the same repository or workspace).

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved