hyperledger/fabric · error
no package.json found at the root of the chaincode package
Error message
no package.json found at the root of the chaincode package
What it means
After scanning all tar headers, ValidateCodePackage requires that at least one entry was named exactly 'src/package.json'. If the Node.js chaincode payload never set foundPackageJson, the package is rejected because the platform cannot treat it as a valid Node.js chaincode project.
Source
Thrown at core/chaincode/platforms/node/platform.go:120
}
if header.Name == "src/package.json" {
foundPackageJson = true
}
// --------------------------------------------------------------------------------------
// Check that file mode makes sense
// --------------------------------------------------------------------------------------
// Acceptable flags:
// ISREG == 0100000
// -rw-rw-rw- == 0666
//
// Anything else is suspect in this context and will be rejected
// --------------------------------------------------------------------------------------
if header.Mode&^0o100666 != 0 {
return fmt.Errorf("illegal file mode detected for file %s: %o", header.Name, header.Mode)
}
}
if !foundPackageJson {
return fmt.Errorf("no package.json found at the root of the chaincode package")
}
return nil
}
// Generates a deployment payload by putting source files in src/$file entries in .tar.gz format
func (p *Platform) GetDeploymentPayload(path string) ([]byte, error) {
var err error
// --------------------------------------------------------------------------------------
// Write out our tar package
// --------------------------------------------------------------------------------------
payload := bytes.NewBuffer(nil)
gw := gzip.NewWriter(payload)
tw := tar.NewWriter(gw)
folder := path
if folder == "" {View on GitHub (pinned to 2736b63f8f)
Solutions
- Place package.json under a src/ directory in the project so it is packaged as 'src/package.json'.
- Re-tar moving the manifest: create a src/ dir containing package.json and the code, then tar that.
- Use the platform's GetDeploymentPayload with the chaincode path so packaging follows the required layout.
- Confirm the chaincode type is 'node' — other platforms (Go, Java) have different manifest requirements.
Example fix
// before (wrong layout in tar) package.json main.js // after (correct layout) src/package.json src/main.js
Defensive patterns
Strategy: validation
Validate before calling
// list tar entries and verify manifest presence before submitting const hasManifest = entries.some(e => e.name === 'src/package.json');
Type guard
function hasSrcPackageJson(entryNames) {
return Array.isArray(entryNames) && entryNames.includes('src/package.json');
} Prevention
- Keep package.json in a src/ subdirectory of the chaincode project
- Never rename or move package.json during builds
- Use Fabric packaging commands to guarantee layout
- Confirm chaincode language type matches the project layout
When it happens
Trigger: ValidateCodePackage receives a .tar.gz with no entry at path 'src/package.json' — e.g. the manifest is at the archive root ('package.json'), in a nested folder, or missing entirely.
Common situations: Packaging the project directory instead of its src subfolder, renaming/moving package.json, using a build tool that flattens the layout, or packaging a non-Node project with the node platform type.
Related errors
- did not find a code package inside the package
- illegal file detected in payload: "%s"
- illegal file detected in payload: "%s"
- illegal file mode detected for file %s: %o
- ChaincodeSpec's path cannot be empty
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/8c1efeedac6047df.
Report an issue: GitHub.