Why does serverless overwrite my go.mod on each build?


I started experimenting with Serverless and Go and so far I’m amazed at how easy things are. I like it!

The one thing that surprised me was that I had issues using my own packages. It turned out my that my module (I am using go mod) had an odd name that I hadn’t given it. I fixed the name, manually built my binaries and happily went on to make and deploy only to find that make fails. What? Another look showed me that the module name was back to the old value. A little while later the culprit was clear - the gomod.sh script overwrites the go.mod file on each execution of the make command.

My question: Why? Is there a reason for this that I do not see?

I fixed the issue for myself by adding a simple check in the script for the existence of go.mod, so I can continue experimenting. But I want to know more about this - maybe there is a specific reason for this behaviour.

Hi @ro-tex, I’m starting with Go now and got the same question, have you figured this out?


Hi @samuelsilva ,

Yes, I did. Here is the ticket I opened and fixed: gomod.sh overwrites go.mod if it exists · Issue #7244 · serverless/serverless · GitHub. I didn’t update this post because I figured it would be released and therefore fixed for everyone. It’s strange that you are still experiencing it. Which version are you using? It looks to me like it’s been released for ages.

The very good news is that the fix is extremely easy and you can easily patch your local code. Here’s the entire change required: Do not overwrite `go.mod` on `make` if it exists. by ro-tex · Pull Request #7245 · serverless/serverless · GitHub

Good luck and all the best,