Unable to launch with other than ${file} in launch.json

294 views
Skip to first unread message

Guyren Howe

unread,
Mar 31, 2019, 2:05:17 PM3/31/19
to Flutter Dev
Using VS Code.

My project folder has a lib/main.dart that I'd like to launch.

My launch.json looks like this:

{
          "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart"
        }
    ]
}

I've also tried "${workspaceFolder}/lib/main.dart" and "${workspaceRoot}/lib/main.dart". Whatever I do, other than "program": "${file}", I get "Target file "lib/main.dart" not found.".

${file} is a workaround, but I have to switch to main.dart every time before I launch, which is annoying.

What is wrong here?

Danny Tuppeny

unread,
Apr 1, 2019, 2:40:23 AM4/1/19
to Flutter Dev
Have you opened a folder further up the tree in VS Code, such that lib/main.dart isn't the correct relative path from the workspace root (eg. is it foo/lib/main.dart)?

Otherwise, if you run the Dart: Capture Logs command (tick just Flutter Run), then hit F5 to launch, then click Stop Logging, it'll open a log file that should include some info on exactly what commands it tried to spawn, with what arguments, and in what folder. That might shed some light on what's happening.

Vikas Jilla

unread,
Apr 1, 2019, 3:44:44 AM4/1/19
to Flutter Dev
May be, Try removing program tag as below

{
   "version": "0.2.0",
   "configurations": [
       {
           "name": "Flutter",
           "request": "launch",
           "type": "dart"
       }
   ]
}

Danny Tuppeny

unread,
Apr 1, 2019, 3:59:20 AM4/1/19
to Vikas Jilla, Flutter Dev
FWIW, removing program like that should just behaves the same as not having a launch.json file at all. If you don't need to customise anything, deleting the launch.json is the preferred option. 

I'm also curious to know why it seems quite common for people to have launch.json files that only have the default values - if you know how/why you ended up with this, please let me know - it might be that we're not doing a good job of explaining how this should work.

--
You received this message because you are subscribed to a topic in the Google Groups "Flutter Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flutter-dev/s70F__AMBvo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guyren Howe

unread,
Apr 1, 2019, 9:05:45 PM4/1/19
to Flutter Dev
I'm afraid I don't understand the first thing ("opened folder…"): how would opening my projects folder above this help, when the relative path is definitely wrong?

The second suggestion (logging) produced a log that contains:
[17:59:25 GMT-0700 (PDT)] [FlutterRun] [Info] Spawning <path to flutter>…
[17:59:25 GMT-0700 (PDT)] [FlutterRun] [Info] ..  in <path of project>

[17:59:26 GMT-0700 (PDT)] [General] [Error] [FlutterRun] Target file "lib/main.dart" not found.


If I concatenate <path of project> with lib/main.dart in my shell, I get the file in question. So this remains just confusing.

Danny Tuppeny

unread,
Apr 2, 2019, 3:24:54 AM4/2/19
to Guyren Howe, Flutter Dev
On Tue, 2 Apr 2019 at 02:05, Guyren Howe <guy...@gmail.com> wrote:
I'm afraid I don't understand the first thing ("opened folder…"): how would opening my projects folder above this help, when the relative path is definitely wrong?

It wouldn't, but it could cause an issue like this. Sometimes people open folders that contain multiple projects (eg. C:\MyRepo but the app they're trying to run it as C:\MyRepo\App). In this case, the path to their entry point is "App\lib\main.dart" instead of just "lib\main.dart".

 
The second suggestion (logging) produced a log that contains:
[17:59:25 GMT-0700 (PDT)] [FlutterRun] [Info] Spawning <path to flutter>…
[17:59:25 GMT-0700 (PDT)] [FlutterRun] [Info] ..  in <path of project>

[17:59:26 GMT-0700 (PDT)] [General] [Error] [FlutterRun] Target file "lib/main.dart" not found.


There should be more logging before this from setting up the debug adapter (starting with "Starting debug session..." and then some info). Could you post everything between that and the bit you posted (or email it to me, redacting as little as you're comfortable with)?

 
If I concatenate <path of project> with lib/main.dart in my shell, I get the file in question. So this remains just confusing.

Yes, that is confusing. If you open a terminal and `cd <path of project>` and run `flutter run -t lib/main.dart` do you see the same issue? 
Reply all
Reply to author
Forward
0 new messages