skip to Main Content

When I am editing a .go source file like that PROJECT_DIR/internal/moduleABC/moduleABC.go and press Start Debugging I get this message "Failed to launch: could not launch process: not an executable file" and then I need to navigate to any of the files in PROJECT_DIR and start debugging again.

Very annoying, maybe someone know a way to fix this.

Thx

Hopefully there is a solution not just for one single module but for all of them.

2

Answers


  1. Chosen as BEST ANSWER

    I edited launch.json and replaced

    "program": "${fileDirname}"
    

    with

    "program": "${workspaceFolder}"
    

    and now the main app is launched even if I am in an internal module folder

    full launch.json file

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch Package",
                "type": "go",
                "request": "launch",
                "mode": "auto",
                "program": "${workspaceFolder}"
            }
        ]
    }
    

  2. It seems like you’re encountering an issue with launching a Golang application from VS Code, especially when working with internal modules. To address this problem, you can follow these steps:

    1. Specify the Entry Point:
      Ensure that you have specified the correct entry point for your Go application in the launch configuration. Open your .vscode/launch.json file, and make sure that the "program" field points to the correct main file or package. For example:
    {   "version": "0.2.0",   
         "configurations": [
    {
      "name": "Launch",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "program": "${workspaceFolder}/internal/moduleABC",
      "env": {},
      "args": []
    }   ] }
    
    1. Use Delve Debugger: Ensure that you have the Delve debugger installed. Delve is a debugger for the Go programming language. You can install it using:
    go get -u github.com/go-delve/delve/cmd/dlv
    

    Then, set the "useApiV1" field to ‘false‘ in your
    launch.json:

    {   "version": "0.2.0",   "configurations": [
    {
      "name": "Launch",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "program": "${workspaceFolder}/internal/moduleABC",
      "env": {},
      "args": [],
      "useApiV1": false
    }   ] }
    
    1. Check Go Module Configuration:
      Make sure your project is using Go modules. If not, initialize modules in your project:
    go mod init
    

    Ensure that your go.mod file has the correct module path.

    1. Update VS Code and Go Extension:
      Ensure that both VS Code and the Go extension are up to date. Extension updates often include bug fixes and improvements.

    2. Reload Window:
      After making changes to your configuration, try reloading the VS Code window. You can do this by clicking on the circular arrow icon in the bottom-left corner of the window.

    If the issue persists, please provide more details about your project structure and the content of your launch.json file, so I can offer more targeted assistance.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search