{"id":11917,"library":"recma-stringify","title":"recma JavaScript Stringifier Plugin","description":"The `recma-stringify` package is a `unified` plugin designed to serialize JavaScript Abstract Syntax Trees (ASTs) back into JavaScript code. It operates within the `recma` ecosystem, which focuses on transforming JavaScript ASTs, similar to how `remark` handles Markdown and `rehype` handles HTML. Currently at version `1.0.0`, it is part of an active project with a stable release cadence that generally aligns with Node.js LTS versions, with major releases dropping support for unmaintained Node.js environments. Its primary differentiator is its seamless integration into the `unified` processing pipeline, abstracting the underlying `estree-util-to-js` utility. This allows developers to easily incorporate JavaScript code generation into broader content processing workflows, such as compiling MDX. It does not parse JavaScript itself; for that, it's typically paired with `recma-parse` or used via the overarching `recma` core package.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/mdx-js/recma#main","tags":["javascript","abstract","ast","compile","plugin","recma-plugin","recma","serialize","typescript"],"install":[{"cmd":"npm install recma-stringify","lang":"bash","label":"npm"},{"cmd":"yarn add recma-stringify","lang":"bash","label":"yarn"},{"cmd":"pnpm add recma-stringify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core ecosystem dependency for plugin integration.","package":"unified","optional":false}],"imports":[{"note":"Package is ESM-only and exports a default function. CommonJS `require` will fail.","wrong":"const recmaStringify = require('recma-stringify')","symbol":"recmaStringify","correct":"import recmaStringify from 'recma-stringify'"},{"note":"Type import for configuring the plugin.","symbol":"Options","correct":"import type { Options } from 'recma-stringify'"},{"note":"`recma-stringify` is a unified plugin and requires `unified` for its processing pipeline.","symbol":"unified","correct":"import { unified } from 'unified'"}],"quickstart":{"code":"import recmaJsx from 'recma-jsx'\nimport recmaStringify from 'recma-stringify'\nimport rehypeParse from 'rehype-parse'\nimport rehypeRecma from 'rehype-recma'\nimport {unified} from 'unified'\n\nasync function processHtmlToJsx() {\n  const file = await unified()\n    .use(rehypeParse, {fragment: true}) // Parse HTML fragment\n    .use(rehypeRecma) // Convert HTML AST (hast) to JS AST (esast)\n    .use(recmaJsx) // Transform JS AST for JSX elements\n    .use(recmaStringify) // Serialize the JS AST back to code\n    .process('<p>Hi!<h1>Hello!') // Process the input string\n\n  console.log(String(file))\n}\n\nprocessHtmlToJsx().catch(console.error)\n","lang":"typescript","description":"Demonstrates processing an HTML fragment through rehype, converting it to a recma (JS) AST, applying JSX transformations, and then stringifying it to output JSX code. This shows the typical `unified` pipeline usage."},"warnings":[{"fix":"Migrate to ES modules and use `import recmaStringify from 'recma-stringify'`.","message":"This package is ESM-only. Direct `require()` statements will result in an `ERR_REQUIRE_ESM` error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to a currently maintained LTS version (e.g., Node.js 18+ for future major releases).","message":"Major version releases of `recma-stringify` (and the unified collective) will drop support for unmaintained Node.js versions. Ensure your Node.js runtime is actively supported.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Implement robust input validation and sanitization for any user-provided JavaScript or content that feeds into the recma pipeline.","message":"The `recma` ecosystem, including `recma-stringify`, works on JavaScript abstract syntax trees. While `recma-stringify` itself generates code, handling and evaluating arbitrary JavaScript can have security implications. Sanitize inputs if they originate from untrusted sources.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your project to use ES Modules (`type: \"module\"` in package.json) and use `import recmaStringify from 'recma-stringify'`.","cause":"Attempting to use `require()` to import `recma-stringify`, which is an ES module.","error":"ERR_REQUIRE_ESM: require() of ES Module .../node_modules/recma-stringify/index.js from ... not supported."},{"fix":"Ensure you are using `import recmaStringify from 'recma-stringify'` and passing the imported function directly to `unified().use()`.","cause":"Incorrectly attempting to instantiate `recmaStringify` with `new` or treating a non-function as a function, often in a CJS context or after a failed default import.","error":"TypeError: recmaStringify is not a function"},{"fix":"Always `await` the result of `unified().process()` as it returns a Promise. Ensure the surrounding function is `async`.","cause":"Missing `await` keyword before `unified().use(...).process(...)` or incorrect chaining in an async context, leading to processing an unresolved Promise.","error":"TypeError: unified(...).use(...).process is not a function"}],"ecosystem":"npm"}