Reputation: 97
I am running into a weird issue while trying to import a local package in my Golang project. I keept getting this error:
could not import PulseGuard/backend/golang/services (no required module provides package "PulseGuard/backend/golang/services")
This is my project Structure
📂 PulseGuard
├── 📂 backend
 │   ├── 📂 databases   Â
 │   │   ├── db.go      ** Database connection setup **
 │   ├── 📂 golang
 │   │   ├── 📂 config/    ** App configurations **
 │   │   ├── 📂 controllers/ **  Business logic (handlers call these) **
 │   │   ├── 📂 routers/   ** Defines routes & maps them to handlers **
 │   │   ├── 📂 services/
 │   │   │   ├── scanner.go   ** Additional service logic (e.g., auth, email) **
 │   │   ├── 📂 models/   ** Database models for GORM **
 │   │   ├── 📂 middleware/ ** Middleware (auth, logging) **
 │   │   ├── go.mod
 │   │   ├── go.sum
 │   │   ├── main.go     # App entry point
My go.mod file looks like this
module PulseGuard
go 1.24.0
require (
github.com/fatih/color v1.18.0
gorm.io/driver/postgres v1.5.11
gorm.io/gorm v1.25.12
)
require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
scanner.go (inside services folder):
package services
import (
"fmt"
"net"
"time"
"github.com/fatih/color"
)
main.go (Inside golang folder):
package main
import (
"fmt"
"PulseGuard/backend/golang/services" // Importing this gives an error
"github.com/fatih/color"
)
What I Tried:
I feel like I'm missing something obvious. Should I be using a different import path? Appreciate any help!
Upvotes: -1
Views: 42
Reputation: 22
please try once as attachment "/" symbol to your import path.
package main
import (
"fmt"
"/PulseGuard/backend/golang/services" // Importing this gives an error - add '/' to path
"github.com/fatih/color"
)
Upvotes: -2