Report this

What is the reason for this report?

Using local packages in serverless functions

Posted on November 25, 2025

I’m having trouble getting doctl to recognize and include locally-defined packages. For example, say I have this project structure in which I have some utility files stored in directory lib/ which are to be shared among different functions (of which “hello” is one). When I try to deploy via doctl serverless deploy functions it fails with

package functions/lib is not in GOROOT (/usr/local/go/src/functions/lib)

How can I fix this?

functions
  lib
    file1.go
    file2.go
  packages
    sample
      hello
        go.mod
        go.sum
        hello.go


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

If I remember correctly, for Go functions the build is always remote, and I think the issue comes from how the Go toolchain inside that environment resolves modules. The lib folder does get included by the Functions builder, but Go itself still expects anything you import to have a proper module path. When it sees something like functions/lib, it assumes you’re trying to import something from GOROOT, which explains the error you saw.

I haven’t tested this exact setup with Go in Functions, but giving the lib folder its own go.mod and importing it using a real module path is usually the safest approach. Something like turning lib into module github.com/you/project/lib and then importing that from your function. I believe the remote build should handle that correctly.

If none of these work, it’s definitely worth opening a support ticket with a minimal example. The Functions team can confirm how the Go runtime handles module resolution in your specific layout.

https://www.digitalocean.com/support/

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.