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.
Case 1, under output
Case 2, when executing build
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 你的目录
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:
No more red flags.