gobuffalo / buffalo

Rapid Web Development w/ Go
http://gobuffalo.io
MIT License
8.08k stars 578 forks source link

Go mod errors. #1488

Closed frederikhors closed 5 years ago

frederikhors commented 5 years ago

I'm trying to use "Go modules" with 0.13.8 Buffalo but I got every time this:

go: error loading module requirements

Buffalo isn't yet 100% compatible with go mod, right?

I'm following this: https://github.com/go-modules-by-example/index/blob/master/003_migrate_buffalo/README.md

markbates commented 5 years ago

It does work with mods. Can you please provide more output and reproducible steps please? That’s not enough information to help you.

markbates commented 5 years ago

I don’t know that article and can’t vouch for its accuracy. If it doesn’t work; you should ask them.

markbates commented 5 years ago

If you’re trying to add mods to a project I recommend deleting any dep or other packagement tools and the vendor directory first. The go mod init and go mod tidy to build your go.mod

frederikhors commented 5 years ago

Amazing. It works now!

frederikhors commented 5 years ago

One advantage of using "Go modules" is to not need the GOPATH env anymore and put the project where you want. Right?

But now when I use "go build" it made an a.go file which imports from my folder (ex: C:\projects\oneProject) and error:

buffalo_build_main.go:12:5: invalid import path: ...

Where am I wrong?

markbates commented 5 years ago

Go modules are experimental. It is recommended by the Go team that you continue to develop within your GOPATH until they are more stable.

You are going wrong because you generated your project in one place and then moved it to another and your module names are mismatched.

You must provide a matching module name and import paths. This is in the go modules documentation.

frederikhors commented 5 years ago

@markbates I'm sorry, I think something is wrong here.

I searched everywhere in issues, but found nothing. This thread is good for newcomers, IMO.

Everything works and everything is good with Buffalo and Go modules.

Just one problem: buffalo build.

It makes a file during build: "_buffalo_buildmain.go":

package main

import (
  "fmt"
  "log"
  "os"
  "os/exec"
  "time"

  "github.com/markbates/grift/grift"
  "github.com/gobuffalo/buffalo/runtime"
  _ "D:/projects/testBuffalo/src/my-project/a"
  _ "D:/projects/testBuffalo/src/my-project/actions"

  "github.com/gobuffalo/packr"
  "github.com/gobuffalo/pop"
  "D:/projects/testBuffalo/src/my-project/models"

  _ "D:/projects/testBuffalo/src/my-project/grifts"

)

func init() {
... everything good here

My project is obviously in: "D:/projects/testBuffalo/src/my-project".

The error is:

ERRO[0017] Error: D:\projects\testBuffalo\src\my-project\buffalo_build_main.go:12:5: invalid import path: "D:/projects/testBuffalo/src/my-project/a" (and 3 more errors)

GOPATH=C:\Users\Fred\go;

My go.mod:

module my-project

require (
    github.com/gobuffalo/buffalo v0.13.8
    github.com/gobuffalo/envy v1.6.10
    github.com/gobuffalo/fizz v1.3.0 // indirect
    github.com/gobuffalo/mw-csrf v0.0.0-20180802151833-446ff26e108b
    github.com/gobuffalo/mw-forcessl v0.0.0-20180802152810-73921ae7a130
    github.com/gobuffalo/mw-i18n v0.0.0-20181027200759-09e0c99be4d3
    github.com/gobuffalo/mw-paramlogger v0.0.0-20181005191442-d6ee392ec72e
    github.com/gobuffalo/packr v1.21.7
  ... and so on

If I use go build it works.

So what I think is maybe something is wrong when generating the file "_buffalo_buildmain.go".

Am I wrong? What do you think?

This problem can help other people.

Thanks.

UPDATE:

Changing GOPATH worked (but Go modules are for not use anymore GOPATH):

GOPATH=C:\Users\Fred\go;D:\projects\testBuffalo;

I really don't understand.