当前位置:网站首页>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 !
边栏推荐
- Brain tree (I)
- Core mode and immediate rendering mode of OpenGL
- How to download and install Weka package
- [paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3
- Software packaging and deployment
- Common operations in VIM
- Yolov4 coco pre train Darknet weight file
- How to package rpm
- Bessie's weight problem [01 backpack]
- Efficient pytorch: how to eliminate training bottlenecks
猜你喜欢

‘make_ unique’ is not a member of ‘std’

Advertising effect cluster analysis (kmeans)

Custom structure type

Judging the number of leap years from 1 to N years

Design and implementation of timer

Use Matplotlib to draw a line chart

Learning C language today is the first time to learn C language. In college, C linguistics is not good, but I want to make progress, so I found a beep video on the Internet to learn C language

Std:: vector minutes

How to cut the size of a moving picture? Try this online photo cropping tool

Master XSS completely from 0 to 1
随机推荐
Common operations in VIM
QT inline dialog
有哪个瞬间让你觉得这个世界出bug了?
Learning notes on February 18, 2022 (C language)
User defined data type - structure
5 connection modes of QT signal slot
Fishing detection software
Position (5 ways)
[untitled] PTA check password
QT excel table read / write library - qtxlsx
55 specific ways to improve program design (1)
Qmake uses toplevel or topbuilddir
Open a restaurant
[C language] 32 keyword memory skills
AB string interchange
Js- get the mouse coordinates and follow them
【Try to Hack】vulnhub DC1
basic_ String mind map
Basic knowledge of pointer
Learning notes on February 5, 2022 (C language)