Skip to content

dart run does not work in flutter projects, or workspaces containing flutter projects #62808

@jakemac53

Description

@jakemac53

This is especially annoying with workspaces, but also valid for regular projects.

Attempting to run dart run <some-script> will result in an error like the following:

dart run melos
Resolving dependencies in `<path>`... 
Because <some-package> requires the Flutter SDK, version solving failed.

Flutter users should use `flutter pub` instead of `dart pub`.

Note the error message also mentions flutter pub - but I never ran dart pub.

Underlying issue

The underlying issue is that dart run attempts to do a dart pub get, and this fails because of the flutter dependency, when using dart which resolves to a normal Dart SDK.

Workarounds

Use dart from the flutter SDK

This does work if you use dart from the flutter SDK.

This is hard to discover though, the error message should ideally tell you this.

We should also maybe consider a flutter dart command? Seems dumb, but would be an easy way to delegate to the dart SDK that is shipped with your flutter SDK.

Use flutter pub run

This also works, but will complain it is deprecated.

Alternate solutions

Could we get an easy way to not run pub get with dart run? The message could then suggest running that way. I thought such an option existed but could not find it via --help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-cliUse area-dart-cli for issues related to the 'dart' command like tool.dart-cli-bugIssues related to the 'dart bug' tool

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions