gitgobackendgo-fiber

Main.go won't run after correct build


I started learning go and made a crm app, just to find that after building main, it won't run.

This is the error shown in the terminal:

PS crm-go-fiber> go build .\main.go
PS crm-go-fiber> go run .\main.exe
main module (github.com/Lo0mi3x/crm-go-fiber) does not contain package github.com/Lo0mi3x/crm-go-fiber/main.exe

I'm new at programming, GitHub, and stuff but I did my commit & push, and everything correct. Even clone the code from my repository and tried it again, but no changes.


Solution

  • You're executing your program incorrectly.

    go build .\main.go
    

    This command compiles and builds main.go. However, you should generally not pass filenames to go build. The better approach is simply go build. But that's not your actual problem here...

    go run .\main.exe
    

    This command attempts to build and run a package called main.exe located in the current directory. The error message you see:

    main module (github.com/Lo0mi3x/crm-go-fiber) does not contain package github.com/Lo0mi3x/crm-go-fiber/main.exe
    

    Is telling you that it cannot find a package caleld main.exe within your current package.

    If you wish to execute the program you compiled in the first command, just execute it as normal:

    .\main.exe