{"record":{"id":"5498c625e0b02993","repo":"gchq/CyberChef","slug":"error-minifying-javascript-result-error","errorCode":null,"errorMessage":"Error minifying JavaScript. (${result.error})","messagePattern":"Error minifying JavaScript\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/JavaScriptMinify.mjs","lineNumber":38,"sourceCode":"        super();\n\n        this.name = \"JavaScript Minify\";\n        this.module = \"Code\";\n        this.description = \"Compresses JavaScript code.\";\n        this.inputType = \"string\";\n        this.outputType = \"string\";\n        this.args = [];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    async run(input, args) {\n        const result = await terser.minify(input);\n        if (result.error) {\n            throw new OperationError(`Error minifying JavaScript. (${result.error})`);\n        }\n        return result.code;\n    }\n\n}\n\nexport default JavaScriptMinify;\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/JavaScriptMinify.mjs#L20-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: invalid syntax fed to terser\nconst code = 'const x = ;';\nconst r = await terser.minify(code); // r.error set\n// after: valid JS\nconst r = await terser.minify('const x = 1;');\nreturn r.code;","handlingStrategy":"try-catch","validationCode":"async function canMinify(src) {\n  const r = await terser.minify(src);\n  if (r.error) throw new Error(`Terser error: ${r.error}`);\n  return true;\n}","typeGuard":"async function isMinifiable(src) {\n  const r = await terser.minify(src);\n  return !r.error;\n}","tryCatchPattern":"try {\n  return await chef.JavaScriptMinify(input);\n} catch (e) {\n  if (/Error minifying JavaScript/.test(e.message))\n    throw new Error('Fix the reported syntax error or upgrade terser');\n  throw e;\n}","preventionTips":["Fix syntax errors terser reports first.","Pre-transpile TypeScript/JSX to plain JS.","Keep terser current with the JS features you use."],"tags":["javascript","minify","terser","parse"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}