{"record":{"id":"d3fe545951fa365d","repo":"parcel-bundler/parcel","slug":"cssnanooptimizer-only-string-contents-are-current","errorCode":null,"errorMessage":"CSSNanoOptimizer: Only string contents are currently supported","messagePattern":"CSSNanoOptimizer: Only string contents are currently supported","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/optimizers/cssnano/src/CSSNanoOptimizer.js","lineNumber":41,"sourceCode":"    if (configFile) {\n      return configFile.contents;\n    }\n  },\n\n  async optimize({\n    bundle,\n    contents: prevContents,\n    getSourceMapReference,\n    map: prevMap,\n    config,\n    options,\n  }) {\n    if (!bundle.env.shouldOptimize) {\n      return {contents: prevContents, map: prevMap};\n    }\n\n    if (typeof prevContents !== 'string') {\n      throw new Error(\n        'CSSNanoOptimizer: Only string contents are currently supported',\n      );\n    }\n\n    const result = await postcss([\n      cssnano((config ?? {}: CSSNanoOptions)),\n    ]).process(prevContents, {\n      // Suppress postcss's warning about a missing `from` property. In this\n      // case, the input map contains all of the sources.\n      from: undefined,\n      map: {\n        annotation: false,\n        inline: false,\n        prev: prevMap ? await prevMap.stringify({}) : null,\n      },\n    });\n\n    let map;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/optimizers/cssnano/src/CSSNanoOptimizer.js#L23-L59","documentation":"Thrown by `CSSNanoOptimizer.optimize` when the incoming bundle contents are not a `string`. cssnano/postcss operate on CSS text, so non-string contents (e.g. a `Buffer` or shared byte buffer) cannot be processed. The optimizer refuses rather than silently coercing.","triggerScenarios":"A CSS bundle whose prior pipeline stage produced non-string contents; an optimizer chain where an earlier optimizer returned a Buffer/Uint8Array; misconfigured bundle type feeding binary into the cssnano optimizer.","commonSituations":"Custom optimizer ordering where a raw/byte optimizer runs before cssnano; assets marked as binary reaching a CSS bundle; version change in a transformer that switches the contents type.","solutions":["Ensure the CSS pipeline keeps contents as a string through to the optimizer.","If you control the upstream stage, return string contents (decode buffers to utf8).","Reorder optimizers so byte-producing optimizers run after cssnano.","Confirm the bundle type is `css` and not mistakenly tagged as a binary type."],"exampleFix":"// before — upstream returns Buffer\nreturn {contents: Buffer.from(css), map};\n// after — keep string\nreturn {contents: css, map};","handlingStrategy":"type-guard","validationCode":"function ensureStringContents(prev) {\n  if (typeof prev !== 'string') throw new Error('cssnano expects string CSS');\n  return prev;\n}","typeGuard":"function isStringContents(c) { return typeof c === 'string'; }","tryCatchPattern":null,"preventionTips":["Keep CSS pipeline contents as strings end-to-end.","Place byte-producing optimizers after cssnano.","Decode buffers to utf8 before returning from upstream optimizers."],"tags":["optimizer","cssnano","css","parcel","type-mismatch"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}