hyperledger/fabric · error
Error writing Chaincode package contents: %s
Error message
Error writing Chaincode package contents: %s
What it means
While packaging the node.js project, util.WriteFolderToTarPackage failed to write the source folder's contents into the tar writer. The platform logs the underlying error and wraps it as 'Error writing Chaincode package contents'. This is a packaging/I/O failure, not a code validation failure.
Source
Thrown at core/chaincode/platforms/node/platform.go:151
payload := bytes.NewBuffer(nil)
gw := gzip.NewWriter(payload)
tw := tar.NewWriter(gw)
folder := path
if folder == "" {
return nil, errors.New("ChaincodeSpec's path cannot be empty")
}
// trim trailing slash if it exists
if folder[len(folder)-1] == '/' {
folder = folder[:len(folder)-1]
}
logger.Debugf("Packaging node.js project from path %s", folder)
if err = util.WriteFolderToTarPackage(tw, folder, []string{"node_modules"}, nil, nil); err != nil {
logger.Errorf("Error writing folder to tar package %s", err)
return nil, fmt.Errorf("Error writing Chaincode package contents: %s", err)
}
// Write the tar file out
if err := tw.Close(); err != nil {
return nil, fmt.Errorf("Error writing Chaincode package contents: %s", err)
}
tw.Close()
gw.Close()
return payload.Bytes(), nil
}
func (p *Platform) GenerateDockerfile() (string, error) {
var buf []string
buf = append(buf, "FROM "+util.GetDockerImageFromConfig("chaincode.node.runtime"))
buf = append(buf, "ADD binpackage.tar /usr/local/src")View on GitHub (pinned to 2736b63f8f)
Solutions
- Check the wrapped underlying error in the message/ logs; fix the root cause it reports.
- Verify the ChaincodeSpec path exists and is readable (ls <path>).
- Re-run packaging after restoring missing/unreadable source files.
- Exclude problematic files (node_modules is already skipped) and retry the package command.
Example fix
// before peer chaincode package -p ./nonexistent-dir -n cc -l node // after peer chaincode package -p ./correct-chaincode-dir -n cc -l node
Defensive patterns
Strategy: try-catch
Validate before calling
const fs = require('fs');
if (!fs.existsSync(chaincodePath) || !fs.statSync(chaincodePath).isDirectory()) {
throw new Error(`Chaincode path ${chaincodePath} does not exist or is not a directory`);
} Try / catch
try {
payload = getDeploymentPayload(spec);
} catch (err) {
if (/Error writing Chaincode package contents/.test(err.message)) {
// check source path exists/readable, fix permissions, then retry once
}
throw err;
} Prevention
- Verify the chaincode directory exists and is readable before packaging
- Check disk space and permissions in the build environment
- Avoid deleting files while packaging is in flight
- Read the wrapped underlying error for the precise root cause
When it happens
Trigger: GetDeploymentPayload called with a folder whose contents cannot be walked or written to the tar stream — missing source directory, unreadable files, or util.WriteFolderToTarPackage returning an error (it excludes 'node_modules').
Common situations: Chaincode path points to a nonexistent or misspelled directory, permission errors on source files, disk or stream failures during tar/gzip writes, or packaging from a path where files were deleted mid-build.
Related errors
- failed to create chaincode package: %s
- failed writing file %s: %v
- error writing config update to output
- error truncating the file [%s] to size [%d]
- error opening block file writer for file %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/ee352fcc088d7cb7.
Report an issue: GitHub.