Getting "No Functions were found in functions directory" error with Go build

Hey! I have been trying to figure it out how to build my Go functions. And almost getting the following error when I run: netlify build:

────────────────────────────────────────────────────────────────
  2. Functions bundling
────────────────────────────────────────────────────────────────

No Functions were found in functions directory

(Functions bundling completed in 110ms)
$ tree functions
/Users/furkan.turkal/go/src/myapp/functions
├──􀀀  api
├──􀀀  go.mod
├──􀀀  go.sum
└──􀀂  sserver
   └──􀀀  main.go

My netlify.toml config:

[build]
base = "./"
command = "pushd web3/ && npm run build && npm run export && popd && pushd functions/ && go build -o api ./server"
publish = "web3/out/"
functions = "functions"

Root dir:

./
├── .git/
├── .gitignore
├── .netlify/
├── functions/
├── netlify.toml
└── web3/

I have web3 and function folder in the root directory. Website builds successfully.

Tried the following example: GitHub - netlify/go-functions-example
I did read the documentation: Deploy Serverless Golang Functions with Netlify

I have github.com/aws/aws-lambda-go v1.17.0 import in my go.mod

$ netlify --version
netlify-cli/9.12.5 darwin-x64 node-v17.6.0

$ go version
go 1.17

Any thoughts?

Also tried following config but no luck:

[build]
base = "./"
command = "pushd web3/ && npm run build && npm run export && popd && pushd functions/ && go build -o api ./server && popd"
publish = "web3/out/"

[build.environment]
GO_IMPORT_PATH = "github.com/Dentrax/myapp/functions"

[functions]
directory = "functions/"

My go.mod:

module github.com/Dentrax/myapp/functions
Deploying to draft URL...
✔ Finished hashing 19 files and 0 functions

My dirs:

❯ netlify functions:list
No functions found in /Users/furkan.turkal/go/src/myapp/functions

❯ netlify functions:invoke
◈ "port" flag was not specified. Attempting to connect to localhost:8888 by default
? Pick a function to trigger (Use arrow keys)

❯ ls functions
api    go.mod go.sum server
────────────────────────────────────────────────────────────────
  1. build.command from netlify.toml
────────────────────────────────────────────────────────────────

$ cd ./functions && go build -o api ./server

(build.command completed in 9.7s)

────────────────────────────────────────────────────────────────
  2. Functions bundling
────────────────────────────────────────────────────────────────

No Functions were found in functions directory

(Functions bundling completed in 155ms)

Hey there, @Dentrax :wave:

Thanks so much for reaching out and providing this information. Welcome to the Netlify Forums! Can you share a link to your site with us?

Hey @hillary,

Here is my preview URL: https://622a4e9338fef32a7e10ddd5--cosigneth.netlify.app

Almost waste my hours to deploy simple Go function, but still I couldn’t figure it out. I wrote custom script today but still no luck. Thanks! :hugs:

#!/usr/bin/env bash

set -euo pipefail

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEBDIR="${DIR}/web3/"
SRVDIR="${DIR}/server/"

pushd $WEBDIR
npm run build
npm run export
popd

mkdir -p functions

pushd $SRVDIR
go build -o "${DIR}/functions/api" ${SRVDIR}/cmd
popd

GOOS=linux
GOARCH=amd64
GO111MODULE=on

This one exits with zero but i still couldn’t see my function’s name in netlify build result.

OK. I think that’s something we can’t solve here. So moved the discussion into here: Does not work with all Go binaries: consider supporting various file types and clarify the build warnings: refactor runtime detection logic · Issue #5 · netlify/elf-cam · GitHub

Created a proposal by debugging Netlify build system end-to-end. Might need some help to improve Go documentation: Build functions with Go | Netlify Docs according to maintainers feedback.

Thanks.

1 Like

hey there dentrax, thanks for pointing this out, and we are discussing this internally!

1 Like