Hi Mark, When importing a module package, the first element in the path must contain a ".". Hence "foo" is invalid. Here is a working example:
$ cd $HOME $ mkdir bar $ cd bar $ go mod init example.com/bar go: creating new go.mod: module example.com/bar $ cat <<EOD >bar.go package bar import "fmt" func Hello() { fmt.Println("Hello from bar!") } EOD $ cd $HOME $ mkdir foo $ cd foo $ go mod init example.com/foo go: creating new go.mod: module example.com/foo $ cat <<EOD >main.go package main import "example.com/bar" func main() { bar.Hello() } EOD $ go mod edit -require=example.com/bar@v0.0.0 -replace=example.com/bar=$HOME/bar $ cat go.mod module example.com/foo require example.com/bar v0.0.0 replace example.com/bar => /root/bar $ go run . Hello from bar! On Fri, 19 Oct 2018 at 21:42, Mark Volkmann <r.mark.volkm...@gmail.com> wrote: > > I have a simple demo application that wants to use a package that is on my > local file system. > The code for the package is in /Users/Mark/foo/bar. > This directory contains the file bar.go which contains: > > package bar > import "fmt" > func Hello() { > fmt.Println("Hello from bar!") > } > > It also contains the file go.mod which just contains: > > module bar > > The demo application in another directory imports this as "foo/bar" in the > file main.go. > It has a go.mod file that contains the following: > > module demo > replace foo/bar => /Users/Mark/foo/bar > > When I enter "go run main.go" in the directory of the demo code I get > build demo: cannot find module for path foo/bar > > Is there something wrong with my use of the "replace" directive? > > None of this code is under the directory pointed to by GOPATH because I'm > trying to use Go modules for everything in this demo. > > -- > R. Mark Volkmann > Object Computing, Inc. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.