{"record":{"id":"bc5b1b2d3cb867a7","repo":"mdx-js/mdx","slug":"expected-fragment-given-to-evaluate","errorCode":null,"errorMessage":"Expected `Fragment` given to `evaluate`","messagePattern":"Expected `Fragment` given to `evaluate`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mdx/lib/util/resolve-evaluate-options.js","lineNumber":70,"sourceCode":" *\n * @param {Readonly<EvaluateOptions> | null | undefined} options\n *   Configuration.\n * @returns {{compiletime: CompileOptions, runtime: RunOptions}}\n *   Split options.\n */\nexport function resolveEvaluateOptions(options) {\n  const {\n    Fragment,\n    baseUrl,\n    development,\n    jsx,\n    jsxDEV,\n    jsxs,\n    useMDXComponents,\n    ...rest\n  } = options || {}\n\n  if (!Fragment) throw new Error('Expected `Fragment` given to `evaluate`')\n  if (development) {\n    if (!jsxDEV) throw new Error('Expected `jsxDEV` given to `evaluate`')\n  } else {\n    if (!jsx) throw new Error('Expected `jsx` given to `evaluate`')\n    if (!jsxs) throw new Error('Expected `jsxs` given to `evaluate`')\n  }\n\n  return {\n    compiletime: {\n      ...rest,\n      development,\n      outputFormat: 'function-body',\n      providerImportSource: useMDXComponents ? '#' : undefined\n    },\n    runtime: {Fragment, baseUrl, jsx, jsxDEV, jsxs, useMDXComponents}\n  }\n}\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/mdx-js/mdx/blob/685627a819567c0788eadb85f5f57065bcc81c2c/packages/mdx/lib/util/resolve-evaluate-options.js#L52-L88","documentation":"resolveEvaluateOptions validates the runtime pieces passed to `evaluate`/`run`. `Fragment` is the component used for JSX fragments (`<>...</>`), and the compiled code references it directly, so it must be supplied. If it is missing, MDX cannot evaluate the generated program and throws immediately.","triggerScenarios":"Calling `evaluate()` (or `run`/`evaluate` via runtime) without `Fragment` in the options object, e.g. `evaluate(code, { jsx, jsxs })` where options come from a spread that omits `Fragment`.","commonSituations":"Hand-writing evaluate options instead of using a helper like `*jsx-runtime` exports; passing only `jsx`/`jsxs` from 'react/jsx-runtime' and forgetting `Fragment`; destructuring options and accidentally dropping `Fragment`; Vue/Solid/Preact setups where the fragment export has a different name and wasn't mapped.","solutions":["Pass `Fragment` from your JSX runtime: `evaluate(code, { ...runtime, Fragment })` with `Fragment` imported from 'react/jsx-runtime' (or the equivalent for your library).","If your library has no `Fragment` export (e.g. Preact's `Fragment` from 'preact'), import and alias it explicitly.","Use the runtime object exported by a `@mdx-js/*` jsx-runtime helper rather than hand-assembling options."],"exampleFix":"// before\nconst result = await evaluate(code, { jsx, jsxs })\n// after\nimport { Fragment, jsx, jsxs } from 'react/jsx-runtime'\nconst result = await evaluate(code, { Fragment, jsx, jsxs })","handlingStrategy":"validation","validationCode":"function assertRuntime(rt) {\n  if (!rt || !rt.Fragment) throw new Error('evaluate options require `Fragment`')\n}","typeGuard":"function hasFragment(rt) {\n  return typeof rt === 'object' && rt !== null && typeof rt.Fragment === 'function'\n}","tryCatchPattern":"try {\n  const result = await evaluate(code, runtime)\n} catch (err) {\n  if (err.message === 'Expected `Fragment` given to `evaluate`') {\n    console.error('Provide Fragment from your jsx-runtime in evaluate options')\n  } else throw err\n}","preventionTips":["Import `Fragment`, `jsx`, `jsxs` (and `jsxDEV` for dev) as one group from the same runtime module.","Build runtime options via a small factory function so required fields can't be omitted.","Reuse the runtime object exported by @mdx-js helpers instead of hand-assembling it."],"tags":["mdx","evaluate","configuration"],"backgroundTag":"missing-required-option","analyzedSha":"685627a819567c0788eadb85f5f57065bcc81c2c","analyzedAt":"2026-09-02T16:11:18.599Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}