"Cannot find module /es5/input/tex.js" error in Windows Node
Created by: curbengh
Issue Summary
I'm trying to integrate mathjax (tex => svg) into this node app (https://github.com/hexojs/hexo-math/pull/130). Unit test ran fine in GitHub Actions' Ubuntu and OSX environments but failed in Windows with MathJax(input/tex): Cannot find module '/es5/input/tex.js'
error (log).
Affects Node 10, 12 & 14. Same issue in Travis.
Steps to Reproduce:
const { init } = require('mathjax');
module.exports = hexo => {
return async function mathjaxFn(args, content) {
if (this.mathjax === false) return content;
const { options: globalCfg } = hexo.config.math.mathjax;
const { mathjax: fmCfg } = this;
const [jsonCfg] = args;
const argsCfg = jsonCfg ? JSON.parse(jsonCfg) : false;
let options = Object.assign({}, globalCfg);
if (fmCfg) options = Object.assign({}, options, fmCfg);
if (argsCfg) options = Object.assign({}, options, argsCfg);
const { conversion, svg, tex } = options;
const MathJax = await init({
loader: {
load: ['input/tex', 'output/svg']
},
tex,
svg
});
const { startup, tex2svgPromise } = MathJax;
const svgOut = await tex2svgPromise(content, conversion);
return startup.adaptor.outerHTML(svgOut);
};
};
Unit test test/index.js
describe('mathjax', () => {
const m = require('../lib/mathjax')(hexo).bind({});
const content = '\\frac{1}{x^2-1}';
const displayFalse = '<mjx-container class="MathJax" jax="SVG">';
const displayTrue = '<mjx-container class="MathJax" jax="SVG" display="true">';
it('default', async () => {
const output = await m(args, content);
output.startsWith(displayFalse).should.eql(true);
});
});
Technical details:
- MathJax Version: 3.0.5
- OS: Windows Server 2019
- Nodejs: v10.21.0, v12.18.2, v14.5.0
Supporting information:
https://github.com/hexojs/hexo-math/pull/130
Configuration ./index.js
mathjax: {
options: {
// https://docs.mathjax.org/en/latest/web/typeset.html#conversion-options
conversion: {
display: false
},
// https://docs.mathjax.org/en/latest/options/input/tex.html
tex: {},
// https://docs.mathjax.org/en/latest/options/output/svg.html
svg: {}
}
}