Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default/automatic launch configs is missing/incorrect if project is nested inside a folder #2365

Closed
trimmdavid opened this issue Apr 18, 2020 · 26 comments
Labels
in debugger Relates to the debug adapter or process of launching a debug session in flutter Relates to running Flutter apps is enhancement
Milestone

Comments

@trimmdavid
Copy link

i keep on having this problem : Your launch config references a program that does not exist. If you have problems launching, check the "program" field in your ".vscode/launch.json" file.

@DanTup
Copy link
Member

DanTup commented Apr 18, 2020

Can you try:

  • Run the Dart: Capture Logs command (untick Analysis Server, but leave everything else ticked)
  • Try to run your app
  • Click Cancel on the logging prompt to stop logging and open the log file
  • Attach the log file here (make sure there's nothing sensitive in it first)

Thanks!

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Apr 18, 2020
@trimmdavid
Copy link
Author

trimmdavid commented Apr 18, 2020 via email

@DanTup
Copy link
Member

DanTup commented Apr 18, 2020

Sorry, I should've been clearer! :-)

  • Open the VS Code command palette by pressing Ctrl+Shift+P (or on macOS, Cmd+Shift+P)
  • Type "capture logs" to filter the command list, and select the Dart: Capture Logs option
  • Untick Analysis Server (those logs aren't relevant here) and click OK

This will start capturing logs from the extension (a notification will be shown in the bottom right corner that they're being captured).

  • Try to launch your app so that you get the original error message from above
  • Click Cancel on the logging notification to stop logging, and open the log file
  • Check the log file doesn't include anything sensitive (it may have path/filenames and other things from your project depending on how long you were capturing)
  • Save the log file and attach it here

Let me know if anything isn't clear. Thanks!

@trimmdavid
Copy link
Author

trimmdavid commented Apr 19, 2020 via email

@DanTup
Copy link
Member

DanTup commented Apr 19, 2020

It looks like in your .vscode/launch.json file, you have:

"program":"bin/main.dart"

However this file doesn't exist in your project. If it's a Flutter project, this should be "lib/main.dart"(or, if you've not customised the launch.json, you can just delete the file altogether).

I'm not sure how you ended up with this file with the wrong value though - bin/main.dart is the default value for a (non-Flutter) Dart project. Did you create this file and select the "Dart" template, or has it been created automatically?

@trimmdavid
Copy link
Author

trimmdavid commented May 6, 2020 via email

@DanTup
Copy link
Member

DanTup commented May 6, 2020

@trimmdavid this happens if your launch.json has a program field that is not on your disk. Please capture a log by:

  • Run the Dart: Capture Logs command
  • Leave everything ticked and click OK
  • Try to start your app so that the error appears
  • Click Cancel on the logging notification to stop logging, and open the log file
  • Copy the log file here

Thanks!

@muhammad-hamza-shahid
Copy link

Hi Dan unluckily I am also facing the same problem, every thing was going fine and suddenly it stopped working and this alert started to appear at bottom right corner of my screen saying

"Your launch config references a program that does not exist. If you have problems launching, check the "program" field in your ".vscode/launch.json" file."

kindly help me out in this problem.

@muhammad-hamza-shahid
Copy link

The above problem is solved, actually I keep on tracking with github so I have the previous working commit of this project, when I checked that out this line:

"program":"bin/main.dart"

It was not their and I didn't made any changes in this file aswell, so I deleted this line and and saved my project and when I reopened it every thing worked fine again like it was working before this error.
Remember I have tried this thing before but I was not closing the editor but when I restarted my editor this alert went of and it started working fine again.

@fabiansalamo
Copy link

Hello, I had this isuue. I solved it by deleting the launch.js file and creating a new config using vs code.

@DanTup
Copy link
Member

DanTup commented Jun 1, 2020

You shouldn't really need a launch.json for simple cases, it should just work without. Some actions in VS Code will trigger creation of a launch.json though. If anyone can reproduce a situation where a launch.json is created and populated incorrectly with bin/main.dart (which is the default for a Dart project, but not Flutter), please let me know!

@ellonsolomon
Copy link

If there are other projects/folders on your vscode workspace, check and correct their ".vscode/launch.json" file configs. Or just remove those projects from the workspace.

@jaerts
Copy link

jaerts commented Jul 1, 2020

Thanks, deleting the launch.js file and without creating a new config solved my debug/run problem.
The problem started after a flutter and dart update.

@DanTup
Copy link
Member

DanTup commented Jul 1, 2020

It sounds like a launch.json is being created automatically with incorrect values in it. If anyone is able to reproduce this (and figure out exactly what they did that triggered this - it might be pressing F5 with certain files open, or when the open folder in VS Code is not directly the project root, etc.), please let me know so I can try to get to the bottom of this. Thanks!

@DanTup DanTup added this to the On Deck milestone Jul 1, 2020
@DanTup DanTup added in debugger Relates to the debug adapter or process of launching a debug session in flutter Relates to running Flutter apps is bug labels Jul 1, 2020
@DanTup DanTup modified the milestones: On Deck, Backlog Jul 2, 2020
@danielbee
Copy link

Hi Dan,
I ran into this and think i now know reproduceable steps.
It comes down to the workspace the user has in vscode.
If the user's root folder is their flutter project, the flow works as expected.
As seen here:
image
This is what i see when i hit F5 on a main.dart without a launch.json, with a workspace that has flutter project as the root folder.

I know that I have an issue which necessitates the use of args on flutter run, which is why i get refused to connect.
"args": ["--web-port", "8080", "--web-hostname","127.0.0.1"]
As an aside, it took me so long to find that out. This should be a check in flutter doctor.

If a user, like me, encounters an issue, a natural thing to do would be to hit that glowing orange settings cog in order to

Configure or Fix launch.Json

I do this and select flutter and dart environment.
It creates a launch.json, but doesn't have the 'program' field in there.

however, if the user is in a larger workspace, when we create the launch.json after hitting F5 from our main.dart followed by the Cog icon; we get the following contents:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Dart",
            "program": "bin/main.dart",
            "request": "launch",
            "type": "dart"
        }
    ]
}

Compare this to the 'working' in the less complicated directory structure.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart"
        }
    ]
}

Note, there's actually a "name" change too..

You've previously mentioned that in a larger workspace, there can be multiple flutter projects, so the flow that creates the launch.json doesn't know where to go.

I see multiple solutions here (without understanding diffculty to implement.)

  • I hit F5 from the main.dart i actually care about. There should be awareness to have this context create a launch.json for that specific file, ie "program" : "{$workspace_root}/path/to/file/i/just/tried/to/run/main.dart"
  • Ensure that there's a comment on creation:
    "program": "bin/main.dart", // Please change this to a path to your main.dart from the workspace root folder
  • Or simply scan through the entire workspace and create multiple launch configs, one for each flutter project. Each config should have a name "Flutter_<flutter_proj_name>"
  • A new CTRL+P option to "Debug from this flutter project", which sets up launch.json.
  • Or all of the above.

I don't use multi-root workspaces, which I think you've mentioned can work.

Let me know if this makes sense and you can also reproduce it.

@DanTup
Copy link
Member

DanTup commented Aug 3, 2020

I know that I have an issue which necessitates the use of args on flutter run, which is why i get refused to connect.
"args": ["--web-port", "8080", "--web-hostname","127.0.0.1"]
As an aside, it took me so long to find that out. This should be a check in flutter doctor.

I'm not sure why using those args would cause this error - please file a bug about that, I believe that should still "just work".

however, if the user is in a larger workspace, when we create the launch.json after hitting F5 from our main.dart followed by the Cog icon; we get the following contents:

Ah, interesting. Can you confirm what your workspace looks like? Have you opened a folder that contains multiple projects, or is it a multi-root workspace with multiple projects?

I hit F5 from the main.dart i actually care about. There should be awareness to have this context create a launch.json for that specific file, ie "program" : "{$workspace_root}/path/to/file/i/just/tried/to/run/main.dart"

Generally if we can infer the file, I'd prefer not to create a launch.json at all. It should only be created when you need to customise something (or want to force a specific program regardless of the open file/project).

A new CTRL+P option to "Debug from this flutter project", which sets up launch.json.

I think this might now be covered by the automatic launch configs?

@DanTup
Copy link
Member

DanTup commented Aug 3, 2020

@danielbee I tried to reproduce what's in your screenshot above, but when I don't have a launch.json the debug side bar shows this welcome view:

Screenshot 2020-08-03 at 14 41 14

How did you get to the the dropdown/cog icon you have without a launch.json?

@danielbee
Copy link

Hi @DanTup,
Many thanks for getting back to me.

My workspace is set-up like this: (A single folder with multiple projects in sub-directories - Compera_app and compera_test are both flutter projects)
image

After I hit F5 from my main.dart, i see the following:
image

Note, I only see the cog after I have hit F5, and during debug. As soon as I close the chrome window or stop (Shift + F5) the application, The debugging screen reverts to what you've shown.

I'm not sure why using those args would cause this error - please file a bug about that, I believe that should still "just work".

Apologies, the opposite is true. Without those args, i get refused to connect. I think my laptop has some organisation/firewall that restricts connections through specific ports. When i don't force the port to be a specific value, dart seems to just give a random port, which doesn't work for me.

Generally if we can infer the file, I'd prefer not to create a launch.json at all. It should only be created when you need to customise something (or want to force a specific program regardless of the open file/project).

When I am given the option to create the launch.json (with the cog shown), i'm already in a debug of a running project; so i'd expect the launch.json to map the program field to the application that is currently being run.

I agree that ideally, we don't need any launch.json. However, In my instance i need to create one to work around organisation security and provide launch-specific args.

@danielbee
Copy link

A new CTRL+P option to "Debug from this flutter project", which sets up launch.json.

I think this might now be covered by the automatic launch configs?

I think this part is what is at fault.
image
If I click 'Create a launch.json file' then I get a launch.json that has the error:

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

If I click show all automatic debug configs:
image
Then after clicking dart & flutter:
image
There are no configurations listed.

@DanTup
Copy link
Member

DanTup commented Aug 5, 2020

My workspace is set-up like this:

Thanks - I can repro. The issue here is that your Flutter project is in a sub-folder, so when VS code asks us for the launch.json contents, it's not clear what we should provide (the root folder is neither a Dart or Flutter project). While we could scan the workspace in this case and find your Flutter project, it's also possible we'd find multiple projects. If we return multiple configs here, VS Code would add all of them to the file.

I'll see if maybe we can take some hints from the current open file, so at least in the case where there's an open file (like in your screenshot) we should find something.

Apologies, the opposite is true. Without those args, i get refused to connect. I think my laptop has some organisation/firewall that restricts connections through specific ports. When i don't force the port to be a specific value, dart seems to just give a random port, which doesn't work for me.

Ah, got it. That makes sense now!

@DanTup DanTup changed the title i cant debug/run my flutter app on visual studio code Default launch.json configuration is incorrect if project is nested inside a folder Aug 5, 2020
@DanTup DanTup removed the awaiting info Requires more information from the customer to progress label Aug 5, 2020
@DanTup
Copy link
Member

DanTup commented Aug 5, 2020

Ok, I think I've come up with a reasonable solution for this. For the "Create launch.config", we'll now locate the project roots and create a launch config for each one. In the example above there was only one, but here's an example where the folder had a Dart project and two Flutter projects in it:

Screenshot 2020-08-05 at 11 26 04

Similarly, for the "Automatic launch configs" we'll now scan each of those project roots, rather than just the main workspace root and also include options for Dart web and Test:

Screenshot 2020-08-05 at 11 25 54

@DanTup DanTup changed the title Default launch.json configuration is incorrect if project is nested inside a folder Default/automatic launch configs is missing/incorrect if project is nested inside a folder Aug 5, 2020
@DanTup DanTup modified the milestones: On Deck, v3.14.0 Aug 5, 2020
@DanTup DanTup closed this as completed in bdc04d8 Aug 5, 2020
@Azhar978
Copy link

i fixed it by replacing package name.

from "bin/main.dart"

to "web/main.dart"

@erayhamurlu
Copy link

erayhamurlu commented Apr 1, 2021

Ekran Resmi 2021-06-02 08 05 59

1- Click debug icon from left side

2- Choose Flutter from dropdown menu

3- Run your project

OR

2- Choose Flutter with your project name

3- Then click create lauch.json

@ranadhaval123
Copy link

ranadhaval123 commented Apr 19, 2021

flutter error

sir i am facing problem in which configuration "flutter_first_application" launch.jason missing

@DanTup
Copy link
Member

DanTup commented Apr 19, 2021

@ranadhaval123 please file a new issue, and include the exact steps that led you to that error. Thanks!

@Azurik52
Copy link

if any of the solutions above didn't help, try to change launch program config like this.

"program" : "Users/smth/your/way/to/file"

Only this helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in debugger Relates to the debug adapter or process of launching a debug session in flutter Relates to running Flutter apps is enhancement
Projects
None yet
Development

No branches or pull requests