hyperledger/fabric · error

chaincode path must be specified

Error message

chaincode path must be specified

What it means

PackageInput.Validate returns this when the --path flag is empty when packaging a chaincode. The path tells the platform registry where to find the chaincode source that gets embedded in the package's code.tar.gz. Without it no deployment payload can be built, so the packaging command refuses to proceed.

Source

Thrown at internal/peer/lifecycle/chaincode/package.go:51

	Command          *cobra.Command
	Input            *PackageInput
	PlatformRegistry PlatformRegistry
	Writer           Writer
}

// PackageInput holds the input parameters for packaging a
// ChaincodeInstallPackage
type PackageInput struct {
	OutputFile string
	Path       string
	Type       string
	Label      string
}

// Validate checks for the required inputs
func (p *PackageInput) Validate() error {
	if p.Path == "" {
		return errors.New("chaincode path must be specified")
	}
	if p.Type == "" {
		return errors.New("chaincode language must be specified")
	}
	if p.OutputFile == "" {
		return errors.New("output file must be specified")
	}
	if p.Label == "" {
		return errors.New("package label must be specified")
	}
	if err := persistence.ValidateLabel(p.Label); err != nil {
		return err
	}

	return nil
}

// PackageCmd returns the cobra command for packaging chaincode

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Re-run the command with the flag: peer lifecycle chaincode package cc.tar.gz --path <path-to-chaincode-source> --lang <lang> --label <label>.
  2. If using variables, verify CC_SRC_PATH is non-empty before invoking the CLI (echo it or add a shell check).
  3. Remember path must point to the chaincode source relative/absolute on the machine running the command, not inside the container.

Example fix

// before (empty input)
p := &PackageInput{Type: "go", Label: "cc_1"}
err := p.Validate() // "chaincode path must be specified"
// after
p := &PackageInput{Path: "../chaincode/fabric-samples/asset-transfer-basic/chaincode-go", Type: "go", Label: "basic_1.0"}
if p.Path == "" {
    return errors.New("chaincode path must be specified")
}
err := p.Validate()
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/bash
: "${CC_SRC_PATH:?Set CC_SRC_PATH to the chaincode source path}"
[ -d "$CC_SRC_PATH" ] || { echo "chaincode path does not exist: $CC_SRC_PATH"; exit 1; }
peer lifecycle chaincode package "$OUT" --path "$CC_SRC_PATH" --lang "$CC_LANG" --label "$LABEL"

Try / catch

if ! out=$(peer lifecycle chaincode package "$OUT" --path "$CC_SRC_PATH" --lang "$LANG_" --label "$LABEL" 2>&1); then
  case "$out" in
    *"chaincode path must be specified"*) echo "Add --path <chaincode source dir>"; exit 2 ;;
    *) echo "$out"; exit 1 ;;
  esac
fi

Prevention

When it happens

Trigger: Running `peer lifecycle chaincode package` without the --path flag, or passing --path "" (e.g. a shell variable that is empty because the env var it referenced was unset).

Common situations: Scripted CI pipelines where CC_SRC_PATH is not exported; copy-pasted commands where the path flag was dropped; packaging a Go chaincode from the wrong working directory and assuming path is optional.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/abadbdcdadfdae04. Report an issue: GitHub.