bug: openpencil query / MCP query_nodes crash on Node — evaluateXPathToNodes is not a function (fontoxpath CJS interop)
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 functionThe 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
npm install -g @open-pencil/[email protected]- Produce any
.fig(openpencil import demo.html -o demo.figworks, or use any existing file) openpencil query demo.fig '//TEXT'- Observe
✗ XPath error: evaluateXPathToNodes is not a function
Root cause
packages/core/src/xpath.ts (built to dist/xpath.js:146) does:
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 functionevaluateXPathToNodes 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:
const { default: PptxGen } = await import("pptxgenjs");dist/xpath.js:197 has the identical problem with evaluateXPathToBoolean, so matchByXPath() is broken as well.
Suggested fix
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
Source: open-pencil/open-pencil