当前位置:网站首页>Solve the go project compilation error go mod: no such file or directory
Solve the go project compilation error go mod: no such file or directory
2022-06-25 15:15:00 【_ Qilixiang】
Catalog
The problem background
mod Schema project , An error is reported. The third-party database cannot be found go.mod file .
Solution
First of all confirm $GOPATH What is the catalog , For example /a/b, Under normal circumstances, there are src、pkg、bin Three directories , The first two directories must .
mod The dependencies downloaded by the schema project will be placed in /a/b/pkg/mod Next .
( Compile any mod Project time )
In an online environment
1, The original go.mod Of documents require Content can copy come out , Then delete the original go.mod and go.sum file ( Rename can also ),
If... Is missing before operation go.mod It doesn't matter ;
2, confirm GO111MODULE Whether the switch is on , If not, it needs to be turned on :
go env -w GO111MODULE=on or export GO111MODULE="on" If you are prompted :warning: go env -w GO111MODULE=... does not override conflicting OS environment variable
Indicates that the variable has been set in the environment variable , At this point to see /etc/profile file , The end of the file must be the environment variable set before ,
If it is off Will
export GO111MODULE="off"
Change it to
export GO111MODULE="on"3, Under project directory go mod init, Will produce an empty go.mod file
4, perform go mod tidy Organize dependencies , You can also carry the currently compiled go edition , Such as :go mod tidy -go=1.16, At this point, we will first finding
If mod Packages to be downloaded under the directory , Will have a found Words come out ; If not, then download Download the words ;
5, Compile : If you are prompted no required module provides package ... to add it: Then the front copy Of mod Paste the content into go.mod In file :
fill go.mod There are two ways to file ,linux Next manual require Add in ,goland The next will be automatically filled to mod file ;
Add go.mod After the document , continue go mod tidy
6, Compile again to succeed
Offline environment
No Faraday fetching dependent packages in offline environment , Therefore, you need to pull down the dependency in the normal compileable environment , Package and transfer to offline environment for compilation .
1, Compile in a normally compileable environment , take mod The directory is compressed ;( Be sure to make sure the package is complete )
2, Offline environment , Upload 、 It's decompressed $GOPATH/pkg/mod Under the table of contents , Confirm the offline environment GO111MODULE It's on ;
3, Recompile, . If mod All the packages are complete , Then the compilation is successful , end .
Otherwise, it will be reported as an error go.mod: no such file or directory, The author's error reporting is the result of this step . Keep looking at the second 4 Step ;
4, If you continue to report this error , The package must be incomplete , Now press the first “ In an online environment ” To deal with , Delete the original go.mod recompile 、 Organize dependencies 、 to mod directories
5, Upload to the offline environment and recompile .
The author has personally waded through the muddy water in both cases , Especially in offline environment, don't be afraid of trouble , After the first compilation, it is packaged and transferred to the offline environment. As a result, the compilation fails ,
The reason is that the package is incomplete , The second compilation found that some packages were downloaded , Therefore, I hope you can solve this problem as soon as possible !
边栏推荐
- QQ情话糖果情话内容获取并保存
- Pytorch | how to save and load pytorch models?
- [paper notes] rethinking and improving relative position encoding for vision transformer
- Customization and encapsulation of go language zap library logger
- System Verilog - thread
- Use Matplotlib to draw a line chart
- Flexible layout (display:flex;) Attribute details
- About?: Notes for
- QQ love talk candy love talk content acquisition and storage
- Js- get the mouse coordinates and follow them
猜你喜欢

Use Matplotlib to draw a line chart

Some usage records about using pyqt5

Introduction to flexible array

1090.Phone List

Ubuntu 20.04 installing mysql8.0 and modifying the MySQL password

Character encoding minutes
![[paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3](/img/28/6d58759a4a4b18923a5ed5ed573956.jpg)
[paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3

basic_ String mind map

Stack and queue

Solution of push code failure in idea
随机推荐
Some usage records about using pyqt5
2. operator and expression multiple choice questions
Design and implementation of thread pool
Study notes of cmake
14 -- validate palindrome string II
15 -- 最接近原点的 K 个点
Luogu p5707 [deep foundation 2. example 12] late for school
2.18 codeforces supplement
[paper notes] semi supervised object detection (ssod)
(2) Relational database
QT animation loading and closing window
NBD Network Block Device
Custom structure type
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
Explanation of dev/mapper
Source code analysis of synergetics and ntyco
C language LNK2019 unresolved external symbols_ Main error
Paddlepaddle paper reproduction course biggan learning experience
Esp8266 building smart home system
Real variable instance