As the project we're working on gets bigger and bigger, a colleague started to face a lot of problems involving pubspec.yaml
. He used to get rid of them by manually deleting Dart's cached dependencies, but this time he's having an issue that looks unsolvable.
When importing libraries within our own package’s lib
directory, import 'package:...'
doesn't work, only relative paths. For instance, consider the following structure:
my_package
└─ lib
├─ utils.dart
└─ api.dart
If he tries to import utils.dart
inside api.dart
, he's restricted to using relative paths:
import 'utils.dart'; // Works!
import 'package:my_package/utils.dart'; // Error: Target of URI doesn't exist: package:my_package/utils.dart.
Such behavior is not consistent, since the project has many other modules in identical contexts that are not required to use relative path to import. Furthermore, no one else in the team was having this problem, but suddenly another on the team started experiencing the same. It's spreading! We tried reinstalling Dart, Flutter, IntelliJ, but the error persists.
The issue disappears if we delete the project and clones it again from git. However, amazingly, the error returns as soon as we restart and invalidate IntelliJ's cache.
Oddly enough, these errors don't interfere with the project's execution, it is still able to run. But since the import is broken the IDE can't link to the file and won't do its regular syntax analysis.
Any ideas on solving this problem, or even how to start looking for solutions?