Snyk JSON to HTML Report Generator
snyk-to-html is a Node.js utility designed to convert the JSON output from various Snyk CLI commands (e.g., `snyk test --json`, `snyk code test --json`, `snyk iac test --json`, `snyk container test --json`) into a human-readable, static HTML vulnerability report. The current stable version is 3.7.1, released in April 2026. The package sees a relatively active release cadence, often featuring bug fixes, security updates, and new features like adding support for exploit maturity, reachability signals, and risk scores. A key differentiator is its ability to accept custom Handlebars templates, allowing users to tailor the report's appearance and included data fields. It is primarily used as a CLI tool but also exposes a programmatic API for integration into automated workflows.
Common errors
-
snyk-to-html: command not found
cause The `snyk-to-html` executable is not in your system's PATH, usually because it wasn't installed globally or its global installation path isn't correctly configured.fixInstall the package globally: `npm install -g snyk-to-html` or ensure your PATH includes `$(npm config get prefix)/bin`. -
Error: Handlebars: Input is not a string
cause The input provided to the templating engine, either directly or via the `convertToHtml` function, was not a valid string.fixEnsure the Snyk JSON output is provided as a string. If using `convertToHtml`, `JSON.stringify()` the object before passing it. -
TypeError: Cannot read properties of undefined (reading 'vulnerabilities')
cause The provided Snyk JSON input is malformed or not in the expected format, causing the report generator to fail when trying to access properties.fixVerify that the input JSON is valid Snyk CLI output. You can use `snyk test --json > output.json` and then validate `output.json` before passing it to `snyk-to-html`.
Warnings
- breaking Node.js 20 or higher is required. Older Node.js versions are not supported.
- breaking The package transitioned to an ESM-first architecture, meaning CommonJS `require()` statements may not work directly for programmatic imports without configuration.
- gotcha Custom Handlebars templates may require updates if new data fields (e.g., `exploitMaturity`, `reachability`, `riskScore`, `epssDetails`) are introduced or existing ones change their structure.
- breaking A Handlebars vulnerability (CVE-2026-33937O) was patched. Ensure you are on the latest patch version to mitigate potential security risks.
Install
-
npm install snyk-to-html -
yarn add snyk-to-html -
pnpm add snyk-to-html
Imports
- convertToHtml
const convertToHtml = require('snyk-to-html').convertToHtml;import { convertToHtml } from 'snyk-to-html'; - SnykToHtmlOptions
import type { SnykToHtmlOptions } from 'snyk-to-html'; - CLI usage (global)
node snyk-to-html -i input.json
snyk-to-html -i input.json -o report.html
Quickstart
import { convertToHtml } from 'snyk-to-html';
import * as fs from 'fs';
const mockSnykJsonOutput = {
"vulnerabilities": [
{
"id": "SNYK-JS-LODASH-590135",
"title": "Prototype Pollution",
"severity": "high",
"description": "The 'merge' function in lodash is vulnerable to prototype pollution via the 'assignValue' function.",
"packageManager": "npm",
"packageName": "lodash",
"version": "4.17.15",
"fixedIn": ["4.17.21"],
"exploitMaturity": "mature"
}
],
"vulnerabilities": [],
"dependencyCount": 1,
"org": "my-org",
"policy": "Snyk Security Policy",
"isPrivate": true,
"summary": "No vulnerabilities found.",
"uniqueCount": 0,
"filesystemPolicy": false,
"licensesPolicy": null
};
async function generateReport() {
try {
const htmlReport = await convertToHtml(JSON.stringify(mockSnykJsonOutput), {
title: 'Snyk Security Report',
// template: fs.readFileSync('./custom-template.hbs', 'utf8') // Optional: use a custom Handlebars template
});
fs.writeFileSync('snyk-report.html', htmlReport);
console.log('HTML report generated: snyk-report.html');
} catch (error) {
console.error('Failed to generate report:', error);
}
}
generateReport();