Go reports an error Finished running tool: path, current directory outside main module .... dependencies solution

This article mainly explains the output error under the go project: Finished running tool: C:\Program Files\Go\bin\go.exe build -o C:\Users\admin\AppData\Local\Temp\vscode-goCewfEl\go -code-check .
current directory outside main module or its selected dependencies workaround.
Author: Ren Congcong
Date: April 19, 2023
Go version: 1.20.3, cursor0.2.5

Error reporting

There is a red mark phenomenon in the idea, and there is a prompt "current directory outside main module or its selected dependencies" in cases 1 and 2.
insert image description here

Case 1, under output

insert image description here

Case 2, when executing build

insert image description here

Reason 1. Directory problem

Explanation: There are Chinese characters or special symbols, which is not the problem of the author. If you find Chinese characters or special symbols in the directory after you check, it is recommended to remove them first, and try to execute the command again in English.

Solution: Modify the file directory to English.

Reason 2: There is no initialization project

Description: No command was used to initialize the project.

Solution:go mod init 你的目录

insert image description here

Tips: This command will generate a mod file in the directory, do not delete it, or an error will be reported after deletion.

After solving:

insert image description here
No more red flags.

Guess you like

Origin blog.csdn.net/hj960511/article/details/130241494