Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot find module /es5/input/tex.js" error in Windows Node #2486

Closed
curbengh opened this issue Jul 30, 2020 · 4 comments
Closed

"Cannot find module /es5/input/tex.js" error in Windows Node #2486

curbengh opened this issue Jul 30, 2020 · 4 comments
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Needed v3 v3.1
Milestone

Comments

@curbengh
Copy link

curbengh commented Jul 30, 2020

Issue Summary

I'm trying to integrate mathjax (tex => svg) into this node app (hexojs/hexo-math#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:

lib/mathjax.js

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:

Supporting information:

hexojs/hexo-math#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: {}
    }
  }
@dpvc
Copy link
Member

dpvc commented Jul 31, 2020

Thanks for the report. It looks like MathJax is having trouble locating its package directory in Windows. I'm able to reproduce the problem, and will look into it further. In the meantime, you can add

        paths: {mathjax: 'mathjax/es5'},

to the loader configuration passed to MathJax's init() function, and that should allow it to work on Windows (and everywhere else). So you would use

    const MathJax = await init({
      loader: {
        paths: {mathjax: 'mathjax/es5'},
        load: ['input/tex', 'output/svg']
      },
      tex,
      svg
    });

See if that works for you.

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team v3 labels Jul 31, 2020
curbengh added a commit to curbengh/hexo-math that referenced this issue Aug 1, 2020
@curbengh
Copy link
Author

curbengh commented Aug 1, 2020

Thanks, WFM in Actions & Travis.

@dpvc
Copy link
Member

dpvc commented Aug 10, 2020

It turns out that the copy of node's path module that webpack uses doesn't understand Windows paths that include backslashes, and that was the source of the problem, here. I've made a PR (see link above) to resolve the issue.

dpvc added a commit to mathjax/MathJax-src that referenced this issue Aug 14, 2020
Fix processing of root directory for components to work under Windows (mathjax/MathJax#2486)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Aug 14, 2020
@dpvc dpvc added this to the 3.1.0 milestone Aug 25, 2020
@dpvc dpvc added Fixed v3.1 and removed Merged Merged into develop branch labels Aug 25, 2020
@dpvc
Copy link
Member

dpvc commented Aug 25, 2020

Fixed in v3.1 released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Needed v3 v3.1
Projects
None yet
Development

No branches or pull requests

2 participants