gchq/CyberChef · error · OperationError
Error minifying JavaScript. (${result.error})
Error message
Error minifying JavaScript. (${result.error}) What it means
Thrown by JavaScript Minify when terser.minify() resolves with a populated result.error rather than throwing - terser reports parse/syntax failures via the returned object. The operation awaits minify, checks result.error, and wraps it.
Source
Thrown at src/core/operations/JavaScriptMinify.mjs:38
super();
this.name = "JavaScript Minify";
this.module = "Code";
this.description = "Compresses JavaScript code.";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
async run(input, args) {
const result = await terser.minify(input);
if (result.error) {
throw new OperationError(`Error minifying JavaScript. (${result.error})`);
}
return result.code;
}
}
export default JavaScriptMinify;
View on GitHub (pinned to 4290ea7539)
Solutions
- Fix the syntax error terser reports in result.error first.
- Upgrade terser to a version supporting the language features used.
- Pre-transpile TSX/TypeScript to plain JS before minifying.
- Confirm the input is actually JavaScript, not JSX/TS without a transform step.
Example fix
// before: invalid syntax fed to terser
const code = 'const x = ;';
const r = await terser.minify(code); // r.error set
// after: valid JS
const r = await terser.minify('const x = 1;');
return r.code; Defensive patterns
Strategy: try-catch
Validate before calling
async function canMinify(src) {
const r = await terser.minify(src);
if (r.error) throw new Error(`Terser error: ${r.error}`);
return true;
} Type guard
async function isMinifiable(src) {
const r = await terser.minify(src);
return !r.error;
} Try / catch
try {
return await chef.JavaScriptMinify(input);
} catch (e) {
if (/Error minifying JavaScript/.test(e.message))
throw new Error('Fix the reported syntax error or upgrade terser');
throw e;
} Prevention
- Fix syntax errors terser reports first.
- Pre-transpile TypeScript/JSX to plain JS.
- Keep terser current with the JS features you use.
When it happens
Trigger: Source code with syntax terser cannot parse: invalid tokens, unsupported/very-recent language features beyond the bundled terser version, malformed input, or unterminated strings/comments.
Common situations: Minifying ES next features with an outdated terser. Feeding non-JS text. Source already minified/obfuscated in ways that confuse the parser. TypeScript/JSX passed without a transpile step.
Related errors
- Unable to parse JavaScript.<br>${e.message}
- Schema ${error}
- Invalid input JSON: ${err.message}
- Unable to parse input as JSON.\n${err}
- ${err}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/5498c625e0b02993.
Report an issue: GitHub.