golang/go · error

%q not allowed in import path

Error message

%q not allowed in import path

What it means

A common mistake is passing a URL (e.g., `https://github.com/pkg/errors`) to `go get` instead of an import path (`github.com/pkg/errors`). The go tool detects http: or https: prefixes on the import path and rejects them with a message naming the offending prefix.

Source

Thrown at src/cmd/go/internal/vcs/vcs.go:834

		// TODO(rsc): This should not be necessary, but it's required to keep
		// tests like ../../testdata/script/mod_get_extra.txt from using the network.
		// That script has everything it needs in the replacement set, but it is still
		// doing network calls.
		return nil, fmt.Errorf("no modules on example.net")
	}
	if importPath == "rsc.io" {
		// This special case allows tests like ../../testdata/script/govcs.txt
		// to avoid making any network calls. The module lookup for a path
		// like rsc.io/nonexist.svn/foo needs to not make a network call for
		// a lookup on rsc.io.
		return nil, fmt.Errorf("rsc.io is not a module")
	}
	// A common error is to use https://packagepath because that's what
	// hg and git require. Diagnose this helpfully.
	if prefix := httpPrefix(importPath); prefix != "" {
		// The importPath has been cleaned, so has only one slash. The pattern
		// ignores the slashes; the error message puts them back on the RHS at least.
		return nil, fmt.Errorf("%q not allowed in import path", prefix+"//")
	}
	for _, srv := range vcsPaths {
		if !str.HasPathPrefix(importPath, srv.pathPrefix) {
			continue
		}
		m := srv.regexp.FindStringSubmatch(importPath)
		if m == nil {
			if srv.pathPrefix != "" {
				return nil, importErrorf(importPath, "invalid %s import path %q", srv.pathPrefix, importPath)
			}
			continue
		}

		// Build map of named subexpression matches for expand.
		match := map[string]string{
			"prefix": srv.pathPrefix + "/",
			"import": importPath,
		}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Remove the http:// or https:// scheme prefix from the path
  2. Use the bare import path: `go get github.com/user/repo` instead of `go get https://github.com/user/repo`
  3. If you need a specific URL, use a replace directive in go.mod

Example fix

# before
go get https://github.com/pkg/errors

# after
go get github.com/pkg/errors
Defensive patterns

Strategy: validation

Validate before calling

# Strip http:// or https:// from import paths before passing to go get
IMPORT_PATH="https://github.com/pkg/errors"
IMPORT_PATH="${IMPORT_PATH#https://}"
IMPORT_PATH="${IMPORT_PATH#http://}"
echo "$IMPORT_PATH"  # github.com/pkg/errors
go get "$IMPORT_PATH"

Try / catch

# Detect URL-in-import-path error and auto-fix
ERR=$(go get "$INPUT" 2>&1)
if echo "$ERR" | grep -q 'not allowed in import path'; then
  CLEANED="${INPUT#https://}"
  CLEANED="${CLEANED#http://}"
  echo "Stripping scheme — retrying: go get $CLEANED"
  go get "$CLEANED"
fi

Prevention

When it happens

Trigger: Running `go get https://github.com/user/repo` or `go get http://example.com/pkg` — the import path starts with 'http:' or 'https:'.

Common situations: Copy-pasting a repository URL from a browser address bar into `go get`; confusion between VCS clone URLs and Go import paths.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/e97e08b19ba6094a. Report an issue: GitHub.