Skip to content

Commit 28ef0e5

Browse files
committed
fix: load MathJax components via file:// URLs in the Node oracle
The tests workflow fails on windows-latest: MathJax's node entry resolves components to plain absolute paths (D:/.../node_modules/mathjax/input/tex.js) and loads them with import(), but Node's ESM loader rejects absolute paths without a URL scheme on Windows ("Only URLs with a scheme in: file, data, and node are supported ... Received protocol 'd:'"). MathJax's own context.path converter deliberately skips the file:// prefix in CJS contexts, so the CJS entry (require('mathjax')) cannot produce import()-compatible paths on Windows. Override the loader's require function to convert absolute paths to file:// URLs (pathToFileURL) before importing; relative paths and node: specifiers pass through unchanged. Behavior on POSIX is unchanged (file:// URLs are equally valid there).
1 parent c87e254 commit 28ef0e5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎utils/check_math_snippets_node.cjs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
'use strict';
1616

17+
const path = require('node:path');
18+
const { pathToFileURL } = require('node:url');
19+
1720
const MERROR_RE = /<merror[^>]*>([\s\S]*?)<\/merror>/g;
1821

1922
function collapse(s) {
@@ -38,7 +41,15 @@ function main() {
3841
}
3942
require('mathjax')
4043
.init({
41-
loader: { load: ['input/tex'] },
44+
loader: {
45+
load: ['input/tex'],
46+
// MathJax's node entry resolves components to plain absolute
47+
// paths and loads them with import(); Node's ESM loader rejects
48+
// absolute paths without a URL scheme on Windows ("Received
49+
// protocol 'd:'"), so convert them to file:// URLs.
50+
require: (file) =>
51+
import(path.isAbsolute(file) ? pathToFileURL(file).href : file),
52+
},
4253
startup: { typeset: false },
4354
})
4455
.then((MathJax) => {

0 commit comments

Comments
 (0)