By Roger Henman
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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.