bug: openpencil query / MCP query_nodes crash on Node — evaluateXPathToNodes is not a function (fontoxpath CJS interop)

Author: JuanitoBGCreated Sep 29, 2026Updated Sep 29, 2026

What happened?

openpencil query always fails under the Node CLI, regardless of file or selector:

$ openpencil query design.fig '//TEXT'
✗ XPath error: evaluateXPathToNodes is not a function

The same code path backs the MCP query_nodes tool, so XPath querying is unusable from any Node-hosted client (CLI and MCP server). openpencil find and openpencil lint work fine.

Platform

CLI

Steps to reproduce

  1. npm install -g @open-pencil/[email protected]
  2. Produce any .fig (openpencil import demo.html -o demo.fig works, or use any existing file)
  3. openpencil query demo.fig '//TEXT'
  4. Observe ✗ XPath error: evaluateXPathToNodes is not a function

Root cause

packages/core/src/xpath.ts (built to dist/xpath.js:146) does:

javascript
const { evaluateXPathToNodes } = await import("fontoxpath");
const nodes = evaluateXPathToNodes(selector, createDocument(graph, page), domFacade);

fontoxpath is a CommonJS package (main: dist/fontoxpath.js, no exports field, no type: module). Under Node's ESM loader it is exposed as a default-only namespace, so the named destructure yields undefined:

$ node -e "import('fontoxpath').then(m => console.log(Object.keys(m), typeof m.evaluateXPathToNodes, typeof m.default?.evaluateXPathToNodes))"
[ 'default', 'module.exports' ] undefined function

evaluateXPathToNodes is undefined, which is why the CLI reports it as "XPath error". It works in the app/browser because the bundler performs CJS interop at build time — it only breaks on Node.

This looks like an oversight for fontoxpath specifically, because the same build already uses the correct pattern for another CJS dependency in dist/io/formats/fig/export.js:39:

javascript
const { default: PptxGen } = await import("pptxgenjs");

dist/xpath.js:197 has the identical problem with evaluateXPathToBoolean, so matchByXPath() is broken as well.

Suggested fix

javascript
const fontoxpath = await import("fontoxpath");
const evaluateXPathToNodes =
  fontoxpath.evaluateXPathToNodes ?? fontoxpath.default.evaluateXPathToNodes;

and the same for evaluateXPathToBoolean.

Version

@open-pencil/[email protected], @open-pencil/[email protected] (npm latest), Windows 11, Node v24.14.1