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

**URL:** <https://forum.serverless.com/t/why-does-serverless-overwrite-my-go-mod-on-each-build/9976>\
**Category:** Serverless Framework\
**Created:** [November 28, 2019, 9:55pm UTC](https://forum.serverless.com/t/why-does-serverless-overwrite-my-go-mod-on-each-build/9976 "2019-11-28T21:55:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ro-tex](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ro-tex/32/3802_2.png) [@ro-tex](https://forum.serverless.com/u/ro-tex)\
**Post date:** [November 28, 2019, 9:55pm UTC](https://forum.serverless.com/t/why-does-serverless-overwrite-my-go-mod-on-each-build/9976/1 "2019-11-28T21:55:02Z")

</div>

Hello!

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.

---

<div class="post-metadata">

**Author:** ![samuelsilva](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/samuelsilva/32/6372_2.png) [@samuelsilva](https://forum.serverless.com/u/samuelsilva)\
**Post date:** [November 22, 2021, 7:34pm UTC](https://forum.serverless.com/t/why-does-serverless-overwrite-my-go-mod-on-each-build/9976/2 "2021-11-22T19:34:24Z")

</div>

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

Thanks.

---

<div class="post-metadata">

**Author:** ![ro-tex](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ro-tex/32/3802_2.png) [@ro-tex](https://forum.serverless.com/u/ro-tex)\
**Post date:** [November 23, 2021, 7:42am UTC](https://forum.serverless.com/t/why-does-serverless-overwrite-my-go-mod-on-each-build/9976/3 "2021-11-23T07:42:21Z")

</div>

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](https://github.com/serverless/serverless/issues/7244). 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](https://github.com/serverless/serverless/pull/7245/files)

Good luck and all the best,  
Ivaylo
