Skip to content

Bad conditional imports are not properly reported by build_modules. #4297

@schultek

Description

@schultek

The build_modules package should nicely report bad or broken imports that cause a compilation failure. This works fine for normal imports, but does not for conditional imports where the conditionally imported part is broken.

Repro:

  1. dart create -t web myapp
  2. Create an empty lib/something.dart file.
  3. Add import 'package:myapp/something.dart' if (dart.library.js_interop) 'package:something/broken.dart'; to web/main.dart.
  4. Run dart run build_runner build

Expected:

Build fails and prints error:

Unable to find modules for some sources, this is usually the result of either a                                                              
  bad import, a missing dependency in a package (or possibly a dev_dependency                                                                  
  needs to move to a real dependency), or a build failure (if importing a                                                                      
  generated file).                                                                                                                             
                                                                                                                                               
  Please check the following imports:    
  
  `import 'package:myapp/something.dart' if (dart.library.js_interop) 'package:myapp/broken.dart';` from myapp|web/main.dart at 3:1

Actual:

Build fails and prints error:

Unable to find modules for some sources, this is usually the result of either a                                                              
  bad import, a missing dependency in a package (or possibly a dev_dependency                                                                  
  needs to move to a real dependency), or a build failure (if importing a                                                                      
  generated file).                                                                                                                             
                                                                                                                                               
  Please check the following imports:    
  

There is no actual import reported after "Please check the following imports: ", which makes it super unhelpful and almost impossible to actually find the problem in a real-world project, especially because someone (me) coming across this doesn't know to look for broken conditional imports and potentially (literally) wastes hours looking for the cause of this.


  • Dart SDK version: 3.10.0 (stable) (Thu Nov 6 05:24:55 2025 -0800) on "macos_arm64"
  • build_modules: 5.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions