当前位置:网站首页>[go] go mod mode, package 12import/add is not in goroot

[go] go mod mode, package 12import/add is not in goroot

2022-06-22 23:46:00 weixin_ forty-three million two hundred and twenty-four thousan

Compile or run  go Engineering Times should be wrong , First look at the environment variables  go env see GO111MODULE What is the status .

There are two cases to deal with

1, The project is mod Pattern
a) If GO111MODULE=on, Let's see if there is go.mod file , If not go mod init once

When it's done go mod tidy that will do ;

b) If GO111MODULE=on, And there are go.mod, directly go mod tidy;

c) If GO111MODULE=off, The open mod Pattern  export GO111MODULE="on", Then go on a)

d) There's another situation , Local go mod If you want to manually transfer the project to linux Compile and run on , If you put go.mod The documents are sent directly to , Will also report this error , The right thing to do is Linux Create a new project under the directory and execute go mod init , Then all documents of the local project, including go.mod Pass it on and then build, It's normal at this time

2, Project not opened mod Pattern
At this time, the default is from $GOPATH Next scan , If it's in linux Compile or run , Then close GO111MODULE:

export GO111MODULE="off"

source /etc/profile

After closing, you can go  env Check again to see if it works ;

If it's in goland Next , Then remove the button -->ok --> Click in the blank space of the mouse to be normal :

 

原网站

版权声明
本文为[weixin_ forty-three million two hundred and twenty-four thousan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222124162566.html