From a065c43a83fd1ceec8d44572b3ccb1a2ce94d957 Mon Sep 17 00:00:00 2001 From: b84330808 Date: Fri, 23 Oct 2026 15:50:15 +0900 Subject: [PATCH] Fix a CommonJS bundle of the Node build throwing on load on Windows When a bundler folds the Node build into a CommonJS file, `import.meta.url` is undefined and `createRequire` falls back to `file:///`. That URL has no drive letter, so on Windows `createRequire` throws ERR_INVALID_ARG_VALUE while the bundle is being loaded, before any document asks for a standard font. Fall back to the root path `/` instead, which is absolute on every platform and resolves the same way as `file:///` elsewhere. Co-Authored-By: Claude Opus 5.5 --- lib/document.node.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/document.node.js b/lib/document.node.js index a212e732..9c9e8d72 100644 --- a/lib/document.node.js +++ b/lib/document.node.js @@ -13,8 +13,10 @@ import { registerFile } from '#fs'; // (CommonJS output) or pointing at a bundle with no `standard-fonts/` directory // next to it (ESM output). Neither may fail before a document actually asks for // a standard font, so the lookup falls back to a base createRequire accepts and -// a failed lookup explains itself. -const require = createRequire(import.meta.url ?? 'file:///'); +// a failed lookup explains itself. The base is the root path `/`, which is +// absolute on every platform; the URL `file:///` has no drive letter, so +// createRequire rejects it on Windows. +const require = createRequire(import.meta.url ?? '/'); const loaders = { Courier: () => require('./standard-fonts/Courier.cjs'),