Failed initializing runtime modules: plugin was built with a different version of package google.golang.org/protobuf/internal/pragma

Was trying to follow video tutorial here: Nakama: Go Runtime | Heroic Labs Documentation

Unfortunately, cannot get it to run. see logs below.

  1. Versions: Nakama 3.14.0, Docker, require GitHub - heroiclabs/nakama-common: The runtime framework for Nakama server. v1.25.0
  2. Server Framework Runtime language: Go 1.19

Logs:

{"level":"error","ts":"2022-11-16T23:39:10.259Z","caller":"server/runtime_go.go:2494","msg":"Could not open Go module","path":"/nakama/data/modules/backend.so","error":"plugin.Open(\"/nakama/data/modules/backend\"): plugin was built with a different version of package google.golang.org/protobuf/internal/pragma"}
{"level":"error","ts":"2022-11-16T23:39:10.260Z","caller":"server/runtime.go:586","msg":"Error initialising Go runtime provider","error":"plugin.Open(\"/nakama/data/modules/backend\"): plugin was built with a different version of package google.golang.org/protobuf/internal/pragma"}
{"level":"fatal","ts":"2022-11-16T23:39:10.260Z","caller":"main.go:146","msg":"Failed initializing runtime modules","error":"plugin.Open(\"/nakama/data/modules/backend\"): plugin was built with a different version of package google.golang.org/protobuf/internal/pragma"}

Dockerfile:

FROM heroiclabs/nakama-pluginbuilder:3.3.0 AS go-builder

ENV GO111MODULE on
ENV CGO_ENABLED 1

WORKDIR /backend

COPY go.mod .
COPY main.go .
COPY vendor/ vendor/

RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so

FROM registry.heroiclabs.com/heroiclabs/nakama:3.14.0

COPY --from=go-builder /backend/backend.so /nakama/data/modules/
COPY local.yml /nakama/data/

go.mod file:

module github.com/technicallyty/nakama-demo

go 1.19

require github.com/heroiclabs/nakama-common v1.25.0

require google.golang.org/protobuf v1.28.1 // indirect

docker-compose.yml:

version: '3'
services:
  postgres:
    command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
    container_name: backend_postgres
    environment:
      - POSTGRES_DB=nakama
      - POSTGRES_PASSWORD=localdb
    expose:
      - "8080"
      - "5432"
    image: postgres:12.2-alpine
    ports:
      - "5432:5432"
      - "8080:8080"
    volumes:
      - data:/var/lib/postgresql/data

  nakama:
    build: .
    container_name: backend
    depends_on:
      - postgres
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama?sslmode=disable &&
        exec /nakama/nakama --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama?sslmode=disable
    expose:
      - "7349"
      - "7350"
      - "7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7350/"]
      interval: 10s
      timeout: 5s
      retries: 5
    links:
      - "postgres:db"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    restart: unless-stopped

volumes:
  data:

Hello @technicallyty, this looks like a dependency pinning issue, have you tried to follow our related guide?

I did look at that, but im not sure how to apply that solution to my problem.

For example, the error is thrown from an internal package from the protobuf import, so i can’t import it as a direct dependency (i.e. using _pragma package - google.golang.org/protobuf/internal/pragma - Go Packages”).

I also can’t just import this: _protobuf module - google.golang.org/protobuf - Go Packages” otherwise i get this error:
Build constraints exclude all the Go files in '/Users/technicallyty/go/pkg/mod/google.golang.org/protobuf@v1.28.1'

I’ve just noticed that in the Dockerfile:
FROM heroiclabs/nakama-pluginbuilder:3.3.0 AS go-builder
should match the Nakama version, so it should be instead
FROM heroiclabs/nakama-pluginbuilder:3.14.0 AS go-builder

Can you please replace and see if this resolves the issue?

/cc @gabriel

ok that gets rid of the other error, but now im getting this:

{"level":"fatal","ts":"2022-11-17T19:13:50.085Z","caller":"server/runtime_go.go:2628","msg":"Error reading InitModule function in Go module","name":"backend"}

here’s the code that sets up the module:

package main

import (
	"context"
	"database/sql"
	"encoding/json"
	"time"

	"github.com/heroiclabs/nakama-common/runtime"
)

func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, iz runtime.Initializer) error {
	initStart := time.Now()

	if err := iz.RegisterRpc("health", RpcHealthCheck); err != nil {
		return err
	}

	logger.Info("module loaded in %ms", time.Since(initStart).Milliseconds())
	return nil
}

type HealthCheckResponse struct {
	Success bool `json:"success"`
}

func RpcHealthCheck(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
	logger.Debug("Healthcheck RPC called")
	response := &HealthCheckResponse{Success: true}

	out, err := json.Marshal(response)
	if err != nil {
		logger.Error("cannot marshal response: %w", err)
		return "", runtime.NewError("cannot marshal response", 13)
	}
	return string(out), nil
}

The InitModule func should have the following signature:
InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, iz runtime.Initializer) error

ahh weird. i swear i copy pasted the signature from the docs… maybe i messed up the selection…

all good and working now though! also noticed that any changes to the code require me to use the flag --build:

docker compose up --build

so it rebuilds the src, at first i thought the updated sig wasn’t working :sweat_smile:

We’ll fix the docs regarding the mismatched versions and consider mentioning the --build flag too in the docs so others don’t run into the same issue.