{"id":11511,"library":"oxc-minify","title":"Oxc Minify","description":"Oxc Minify is a JavaScript minifier built in Rust, providing a Node.js API for synchronous and asynchronous code minification. Currently at version 0.126.0, it is under active and rapid development, with frequent releases often introducing breaking changes as the project matures. It is designed for high performance, already outperforming `esbuild` in some benchmarks, and aims to eventually include advanced minification techniques like constant inlining and dead code removal. A key differentiator is its Rust-based architecture, offering potential speed advantages over JavaScript-based minifiers like Terser or UglifyJS. However, it is explicitly alpha software, making assumptions about semantically correct input and using a fast parsing mode that skips some semantic error checks to maximize performance.","status":"active","version":"0.126.0","language":"javascript","source_language":"en","source_url":"https://github.com/oxc-project/oxc","tags":["javascript","minifier","minify","oxc","terser","typescript","uglify"],"install":[{"cmd":"npm install oxc-minify","lang":"bash","label":"npm"},{"cmd":"yarn add oxc-minify","lang":"bash","label":"yarn"},{"cmd":"pnpm add oxc-minify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime environment requirement for the Node.js API.","package":"node","optional":false}],"imports":[{"note":"The documentation primarily shows ESM `import` syntax. While CommonJS might work for some versions/environments, ESM is the officially demonstrated approach. Ensure your project is configured for ESM.","wrong":"const { minifySync } = require('oxc-minify');","symbol":"minifySync","correct":"import { minifySync } from 'oxc-minify';"},{"note":"`minify` is the asynchronous version, useful for I/O-bound or concurrent tasks. Both `minify` and `minifySync` are named exports.","wrong":"import minify from 'oxc-minify'; // Not a default export","symbol":"minify","correct":"import { minify } from 'oxc-minify';"},{"note":"Import types separately using `import type` for TypeScript projects.","symbol":"MinifyOptions","correct":"import type { MinifyOptions } from 'oxc-minify';"}],"quickstart":{"code":"import { minifySync } from \"oxc-minify\";\n\nconst filename = \"test.js\";\nconst code = \"const x = 'a' + 'b'; console.log(x); function sum(a, b) { return a + b; } console.log(sum(1,2));\";\nconst options = {\n  compress: {\n    target: \"esnext\",\n    // Example of a common compression option\n    inline: 2 // Inline small functions where possible\n  },\n  mangle: {\n    toplevel: false,\n    // Example of a common mangling option\n    properties: false // Do not mangle properties for now\n  },\n  codegen: {\n    removeWhitespace: true,\n    // Example of a common code generation option\n    quote: 'single' // Use single quotes for strings\n  },\n  sourcemap: true,\n};\n\n// Synchronous minification\nconst resultSync = minifySync(filename, code, options);\nconsole.log('Synchronous result:');\nconsole.log(resultSync.code);\n// console.log(resultSync.map); // Source map can be logged if needed\n\n// Asynchronous minification (uncomment to use)\n// (async () => {\n//   const resultAsync = await minify(filename, code, options);\n//   console.log('\\nAsynchronous result:');\n//   console.log(resultAsync.code);\n//   // console.log(resultAsync.map);\n// })();","lang":"typescript","description":"This example demonstrates both synchronous and asynchronous minification of a JavaScript code string, showcasing common options for compression, mangling, and code generation, along with sourcemap generation."},"warnings":[{"fix":"Review your Rust FFI bindings or custom allocator usage to align with the new method names in `oxc_allocator`.","message":"The `allocator` module's `Box` and `Vec` methods were renamed, which can affect custom Rust-based extensions or deeper integrations.","severity":"breaking","affected_versions":">=0.126.0"},{"fix":"Update any code relying on `oxc_str` or `oxc_span` string type re-exports according to the new API and macro usage.","message":"The `oxc_str` crate underwent multiple breaking changes, including the removal of identity `FromIn` impl for `Ident` and re-exports of string types from `oxc_span`, along with the introduction of a new `static_ident!` macro.","severity":"breaking","affected_versions":">=0.125.0"},{"fix":"Thoroughly test minified output in your target environment. Monitor the Oxc project's GitHub releases for updates on feature completeness and stability. Avoid using in production without extensive validation.","message":"Oxc Minify is currently alpha software and may produce incorrect results or not fully optimize code as expected. It lacks some advanced minification techniques like constant inlining and dead code removal.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure your input code is syntactically and semantically valid before passing it to `oxc-minify`. Use linters or other parsers (e.g., `oxc-parser` in full mode) for prior validation if semantic correctness is not guaranteed.","message":"To maximize performance, `oxc-minify` assumes the input code is semantically correct. It uses a fast parsing mode that skips checks for semantic errors related to symbols and scopes.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Adjust any direct Rust-level integrations to align with the revised module structure and exports.","message":"Oxlint's internal `span` and `str` crate re-exports were removed, potentially impacting applications that directly interfaced with these internal Rust crates.","severity":"breaking","affected_versions":">=0.125.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Always provide a string for the `filename` argument, even if it's a placeholder like `'input.js'`.","cause":"The `filename` parameter in `minifySync` or `minify` was not provided or was `undefined`.","error":"Error: The 'filename' argument must be of type string. Received type undefined"},{"fix":"Ensure the input `sourceText` is valid JavaScript/TypeScript. `oxc-minify` expects semantically correct code and may not gracefully handle all malformed inputs.","cause":"Input code contains syntax errors that `oxc-minify`'s parser cannot handle, potentially due to unsupported syntax or malformed code.","error":"SyntaxError: Expected an identifier but found 'class'"},{"fix":"Wrap your minification call in a `try...catch` block for `minifySync` or use `.catch()` for `minify` to handle potential errors during the minification process.","cause":"The `minifySync` or `minify` function might have thrown an error, causing `result` to be undefined, and then you tried to access `result.code`.","error":"TypeError: Cannot read properties of undefined (reading 'code')"}],"ecosystem":"npm"}