3
votes

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?

2
i had the same issue using vs code and i came across an answer that is because your flutter project is in a sub-folder of the folder open in Code not sure if it applies ti intelliJ stackoverflow.com/a/47831134/10409567 - griffins
@Ggriffo I checked your link, but that's not our case, unfortunately. Thanks. - MarcG
It's a bug I've been encountering recently on vscode too. Usually reloading the IDE is enough. Likely a bug - Rémi Rousselet
use flutter build clean then restart the ide - Payam Khaninejad

2 Answers

1
votes

This was solved in Flutter v1.9.1+hotfix.2.

0
votes

If you are using android studio , just use invalidate cache + restart option https://prnt.sc/1q2h8j7 (check screenshot)