hyperledger/fabric · error

Could not find config file. Please make sure that FABRIC_CFG

Error message

Could not find config file. Please make sure that FABRIC_CFG_PATH is set to a path which contains peer.yaml

What it means

This error is thrown by InitConfig in internal/peer/common/common.go when Viper fails to read the command's YAML config file (e.g. peer.yaml). The Hyperledger Fabric viper version reports 'Unsupported Config Type' when the file simply isn't found, so the code translates that into a clearer message telling the user FABRIC_CFG_PATH must point to a directory containing the expected <cmdRoot>.yaml. It is an environment/configuration setup problem, not a code bug.

Source

Thrown at internal/peer/common/common.go:139

	GetOrdererEndpointOfChainFnc = GetOrdererEndpointOfChain
	GetDeliverClientFnc = GetDeliverClient
	GetPeerDeliverClientFnc = GetPeerDeliverClient
	GetClientCertificateFnc = GetClientCertificate
}

// InitConfig initializes viper config
func InitConfig(cmdRoot string) error {
	err := config.InitViper(nil, cmdRoot)
	if err != nil {
		return err
	}

	err = viper.ReadInConfig() // Find and read the config file
	if err != nil {            // Handle errors reading the config file
		// The version of Viper we use claims the config type isn't supported when in fact the file hasn't been found
		// Display a more helpful message to avoid confusing the user.
		if strings.Contains(fmt.Sprint(err), "Unsupported Config Type") {
			return errors.New(fmt.Sprintf("Could not find config file. "+
				"Please make sure that FABRIC_CFG_PATH is set to a path "+
				"which contains %s.yaml", cmdRoot))
		} else {
			return errors.WithMessagef(err, "error when reading %s config file", cmdRoot)
		}
	}

	return nil
}

// InitBCCSPConfig initializes BCCSP config
func InitBCCSPConfig(bccspConfig *factory.FactoryOpts) error {
	SetBCCSPKeystorePath()

	subv := viper.Sub("peer.BCCSP")
	if subv == nil {
		return fmt.Errorf("could not get peer BCCSP configuration")
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Set FABRIC_CFG_PATH to the directory containing peer.yaml, e.g. export FABRIC_CFG_PATH=$PWD/ or /etc/hyperledger/fabric (sampleconfig is in the fabric source tree).
  2. Verify the file exists: ls $FABRIC_CFG_PATH/peer.yaml; if missing, copy sampleconfig/peer.yaml from the fabric repo.
  3. In Docker, mount the config: -v <host-config>:/etc/hyperledger/fabric and confirm the peer container's FABRIC_CFG_PATH env var matches.
  4. If the file exists but is malformed/unreadable, fix permissions or YAML syntax, then retry.

Example fix

// before (config not found)
peer node start

// after (set config path first)
export FABRIC_CFG_PATH=/etc/hyperledger/fabric
peer node start
Defensive patterns

Strategy: validation

Validate before calling

cfgPath := os.Getenv("FABRIC_CFG_PATH")
if cfgPath == "" {
	return fmt.Errorf("FABRIC_CFG_PATH is not set")
}
if _, err := os.Stat(filepath.Join(cfgPath, "peer.yaml")); err != nil {
	return fmt.Errorf("%s does not contain peer.yaml", cfgPath)
}

Try / catch

if err := common.InitConfig(cmdRoot); err != nil {
	if strings.Contains(err.Error(), "Could not find config file") {
		log.Fatalf("config setup: set FABRIC_CFG_PATH to a dir containing %s.yaml: %v", cmdRoot, err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling InitConfig (via peer InitCmd, or test helpers initPeerTestEnv/initOrdererTestEnv) when viper.ReadInConfig() fails with an error containing 'Unsupported Config Type' — i.e. FABRIC_CFG_PATH is unset, empty, or points to a directory that does not contain <cmdRoot>.yaml (peer.yaml for the peer binary).

Common situations: Running the peer node without exporting FABRIC_CFG_PATH; pointing FABRIC_CFG_PATH at the wrong directory (e.g. the crypto-config dir instead of the sampleconfig dir); renaming or deleting peer.yaml; running binaries outside the fabric-samples environment; Docker containers started without the config volume mounted.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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