转到模块-替换不起作用-没有版本的替换模块必须是目录路径(已root或以 [英] go modules - replace does not work - replacement module without version must be directory path (rooted or starting with
问题描述
我只想通过go模块使用本地包.
I just want to use a local package using go modules.
我在goweb文件夹中有这些文件:
I have these files in a folder goweb:
和go.mod
模块goweb
go 1.12
require mypack v0.0.0
replace mypack => ./src/mypack
但是go.mod
抱怨:
replacement module without version must be directory path (rooted or starting with .
去-u ./...
go: parsing src/mypack/go.mod: open <local path>/goweb/src/mypack/go.mod: no such file or directory
go: error loading module requirements
所以我在这里缺少一些路径结构
So I am missing some path structure here
推荐答案
如果您的应用程序及其使用的包是同一go模块的一部分,则不必将其添加到go.mod
中,只需引用
If your app and the package it uses are part of the same go module, you don't have to add it to go.mod
, you can just refer to it.
如果它们不是同一go模块的一部分,则可以按照以下步骤操作:
If they are not part of the same go module, then you can follow these steps:
您为replace
指令指定的路径必须是绝对路径或相对路径,相对于模块根目录.
The path you specify for the replace
directive must be either an absolute path or a relative path, relative to the module's root.
因此,如果mypack
是模块根目录的同级对象,则可以使用以下代码:
So if mypack
is a sibling of your module's root, you could use this:
replace mypack => ../mypack
此外,要执行此操作,还必须将mypack
转换为go模块(mypack
必须包含go.mod
文件).在其文件夹中运行go mod init mypack
.
Also, for this to work, you also have to "convert" mypack
into a go module (mypack
must contain a go.mod
file). Run go mod init mypack
in its folder.
这篇关于转到模块-替换不起作用-没有版本的替换模块必须是目录路径(已root或以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!