prettier/prettier · error · UnexpectedNodeError

Unexpected PostCSS node type: ${JSON.stringify(node.type)}.

Error message

Unexpected PostCSS node type: ${JSON.stringify(node.type)}.

What it means

The CSS/SCSS/Less printer's switch statement handles every known PostCSS AST node type. The default branch (src/language-css/printer-postcss.js:511-513) throws UnexpectedNodeError if a node type is not recognized. This is marked `c8 ignore` — it is a defensive invariant never expected to fire; hitting it means the parser produced a node the printer does not know how to render.

Source

Thrown at src/language-css/printer-postcss.js:513

      return printString(
        node.raws.quote + node.value + node.raws.quote,
        options,
      );

    case "value-atword":
      return ["@", node.value];

    case "value-unicode-range":
      return node.value;

    case "value-unknown":
      return node.value;

    case "front-matter": // Handled in core
    case "value-comma": // Handled in `value-comma_group`
    default:
      /* c8 ignore next */
      throw new UnexpectedNodeError(node, "PostCSS");
  }
}

const printer = {
  features: {
    experimental_frontMatterSupport: {
      massageAstNode: true,
      embed: true,
      print: true,
    },
  },
  print: genericPrint,
  embed,
  insertPragma,
  massageAstNode,
  getVisitorKeys,
};

View on GitHub (pinned to 903845c7d1)

Solutions

  1. Upgrade prettier to the latest version that may recognize the new node type.
  2. Identify the offending CSS construct from the reported node type and simplify or remove it.
  3. Disable the custom postcss/plugin pipeline and re-run to isolate whether a plugin injected the node.
  4. If reproducible on current prettier, file an issue with the minimal CSS snippet and node type.
Defensive patterns

Strategy: try-catch

Validate before calling

const SUPPORTED_TYPES = new Set([/* enumerate css node types your tooling uses */]);
// Walk the PostCSS AST and assert node.type is in SUPPORTED_TYPES before formatting.

Try / catch

try {
  await prettier.format(css, { parser: "css" });
} catch (error) {
  if (error.name === "UnexpectedNodeError") {
    console.error("Unsupported CSS node type:", error.node?.type);
  } else throw error;
}

Prevention

When it happens

Trigger: A new or experimental PostCSS/postcss-values parser node type the current printer version doesn't handle. A custom plugin that injects synthetic PostCSS nodes with an unknown type. A version mismatch between the bundled postcss parser and the printer.

Common situations: Upgrading postcss or a postcss plugin independently of prettier. Using bleeding-edge or non-standard CSS syntax. A third-party plugin mutating the AST after parsing.

Related errors


AI-assisted analysis of prettier/prettier@903845c7d1 (2026-08-09). Data as JSON: /api/errors/80c178dc369e97f2. Report an issue: GitHub.