{"record":{"id":"631d4a4bc8552460","repo":"hyperledger/fabric","slug":"the-local-msp-must-have-an-id","errorCode":null,"errorMessage":"the local MSP must have an ID","messagePattern":"the local MSP must have an ID","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/common/common.go","lineNumber":183,"sourceCode":"\tif err := subv.Unmarshal(&bccspConfig, opts); err != nil {\n\t\treturn errors.WithMessage(err, \"could not decode peer BCCSP configuration\")\n\t}\n\n\treturn nil\n}\n\n// InitCrypto initializes crypto for this peer\nfunc InitCrypto(mspMgrConfigDir, localMSPID, localMSPType string) error {\n\t// Check whether msp folder exists\n\tfi, err := os.Stat(mspMgrConfigDir)\n\tif err != nil {\n\t\treturn errors.Errorf(\"cannot init crypto, specified path \\\"%s\\\" does not exist or cannot be accessed: %v\", mspMgrConfigDir, err)\n\t} else if !fi.IsDir() {\n\t\treturn errors.Errorf(\"cannot init crypto, specified path \\\"%s\\\" is not a directory\", mspMgrConfigDir)\n\t}\n\t// Check whether localMSPID exists\n\tif localMSPID == \"\" {\n\t\treturn errors.New(\"the local MSP must have an ID\")\n\t}\n\n\t// Init the BCCSP\n\tbccspConfig := factory.GetDefaultOpts()\n\terr = InitBCCSPConfig(bccspConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tconf, err := msp.GetLocalMspConfigWithType(mspMgrConfigDir, bccspConfig, localMSPID, localMSPType)\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = mspmgmt.GetLocalMSP(factory.GetDefault()).Setup(conf)\n\tif err != nil {\n\t\treturn errors.WithMessagef(err, \"error when setting up MSP of type %s from directory %s\", localMSPType, mspMgrConfigDir)\n\t}\n","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/common/common.go#L165-L201","documentation":"InitCrypto checks that a local MSP ID was supplied before initializing the local MSP. If localMSPID is the empty string (CORE_PEER_LOCALMSPID unset or the corresponding flag empty), it returns this error because the peer cannot know which organization the local MSP represents.","triggerScenarios":"Calling InitCrypto (via peer InitCmd) with localMSPID == \"\" — typically CORE_PEER_LOCALMSPID not set in the environment and not provided via flags/config while starting or operating the peer.","commonSituations":"Running the peer container without -e CORE_PEER_LOCALMSPID=Org1MSP; clearing core.yaml's peer.localMSPId during customization; scripted environments losing the env var across sudo/su; joining an org with a renamed MSP ID but not updating the peer config.","solutions":["Set the env var: export CORE_PEER_LOCALMSPID=Org1MSP (matching the MSP ID in the MSP dir's config).","Or set peer.localMSPId in core.yaml / FABRIC_CFG_PATH's peer.yaml.","Confirm the value matches the id inside $CORE_PEER_MSPCONFIGPATH/config.yaml / the MSP's metadata, not just any string.","In Docker Compose, add CORE_PEER_LOCALMSPID to the peer service's environment block."],"exampleFix":"// before (docker-compose peer env missing)\nenvironment:\n  - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp\n\n// after\nenvironment:\n  - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp\n  - CORE_PEER_LOCALMSPID=Org1MSP","handlingStrategy":"validation","validationCode":"localMSPID := os.Getenv(\"CORE_PEER_LOCALMSPID\")\nif localMSPID == \"\" {\n\treturn errors.New(\"CORE_PEER_LOCALMSPID must be set (e.g. Org1MSP) before starting the peer\")\n}","typeGuard":null,"tryCatchPattern":"if err := common.InitCrypto(mspDir, localMSPID, localMSPType); err != nil {\n\tif strings.Contains(err.Error(), \"the local MSP must have an ID\") {\n\t\treturn fmt.Errorf(\"set CORE_PEER_LOCALMSPID or peer.localMSPId in core.yaml: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Always define CORE_PEER_LOCALMSPID in peer container environments and docker-compose templates.","Keep peer.localMSPId in core.yaml as a fallback so env loss doesn't break startup.","Assert the MSP ID in entrypoint scripts and fail fast with a clear message.","Match the ID exactly to the MSP defined in the channel/org configuration."],"tags":["hyperledger-fabric","msp","configuration","env-var"],"backgroundTag":"missing-env-var","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}