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

  1. Fix the syntax error terser reports in result.error first.
  2. Upgrade terser to a version supporting the language features used.
  3. Pre-transpile TSX/TypeScript to plain JS before minifying.
  4. 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

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


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/5498c625e0b02993. Report an issue: GitHub.