Flutter imports randomly stop working, for no apparent reason

512

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

Share:
512
MarcG
Author by

MarcG

Currently living in São Paulo and Rio de Janeiro - Brazil. I hold both Brazilian and European (Polish) passports. Aeronautical-Mechanical Engineer (Technological Institute of Aeronautics ITA, the "Brazilian MIT"). MBA (PUC-RJ) Software Architect and Developer. Previously C++, but now mostly Dart/Flutter (see https://pub.dev/publishers/glasberg.dev/packages), JavaScript (Typescript) and Java. Love TDD, BDD and Clean Code. Also very interested in Usability and Gamification. Excellent communication skills and technical writing. I program since I was 10 yo. Love travelling, astronomy, science and games (playing and making them). Links: https://github.com/marcglasberg https://www.linkedin.com/in/marcglasberg/ https://medium.com/flutter-community/https-medium-com-marcglasberg-async-redux-33ac5e27d5f6 https://medium.com/flutter-community/i18n-extension-flutter-b966f4c65df9 Patents: https://www.google.com/patents/US7917437 https://www.google.com/patents/US7596530 Fluent English and Portuguese, good Spanish, some French. Come visit Rio and rent my place in AirBnB: https://www.airbnb.com/rooms/13830632 [email protected]

Updated on December 13, 2022

Comments

  • MarcG
    MarcG over 1 year

    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?