mathjax / MathJax-node

MathJax for Node
Apache License 2.0
615 stars 97 forks source link

Error: Cannot read property 'readFile' of null (SRE) #274

Closed miguelBinpar closed 7 years ago

miguelBinpar commented 7 years ago

Hi there,

I'm trying to use this package in a Meteor/React app and I'm experiencing a problem that seems to be related to sre.

I get an error when I try to require the MathJax API:

let mjAPI = require("mathjax-node/lib/mj-single.js");

And here's the error I'm getting:

Error: Cannot read property 'readFile' of null
TypeError: Cannot read property 'readFile' of null
    at Function.sre.MathMap.fromFile_ (sre.js:326)
    at Function.sre.MathMap.retrieveFiles (sre.js:323)
    at sre.MathMap.retrieveMaps (sre.js:325)
    at new sre.MathMap (sre.js:320)
    at Function.a.getInstance (sre.js:18)
    at sre.SpeechRuleEngine.updateEngine (sre.js:566)
    at sre.SpeechRuleEngine.parameterize_ (sre.js:554)
    at sre.SpeechRuleEngine.parameterize (sre.js:554)
    at sre.System.setupEngine (sre.js:610)
    at sre.js (sre.js:623)

I've seen you are planning to remove sre from the package and that you are working on it right now. Will this be fixed when that's done or it's just something I'm doing wrong or simply forgetting about?

Thanks in advance. Best regards, Miguel.

pkra commented 7 years ago

I cannot reproduce this. A minimal example that breaks would be helpful. If you can additionally test the develop branch, that'd be useful.

miguelBinpar commented 7 years ago

I can't give you more detailed example than the line:

let mjAPI = require("mathjax-node/lib/mj-single.js");

because that's the line where it breaks. I haven't been able to go further using the module.

I'll try to test the develop branch and bring the results here.

pkra commented 7 years ago

Do the examples in ./bin work for you?

pkra commented 7 years ago

Also, more background on the setup (versions, OSs etc) would be helpful.

miguelBinpar commented 7 years ago

Examples seem to work fine.

About my setup:

I'm trying to use the develop branch but I've never done that (I'm getting started with git and all its features), so I'm having some troubles. Will bring more info asap.

Thanks a lot for your interest in the issue, I really appreciate it.

pkra commented 7 years ago

Thanks.

(I'm getting started with git and all its features),

Just replace the mathjax-node line in your package.json with mathjax/mathjax-node#develop, cf. https://docs.npmjs.com/files/package.json#github-urls.

miguelBinpar commented 7 years ago

Great, thanks! I'm on it!

miguelBinpar commented 7 years ago

Here's the thing:

It seems like your module needs jsdom, which can use 'canvas' module... and here's what I get:

Unable to resolve some modules:

  "canvas" in /Users/miguel/Proyectos/ProMIR/LMS/node_modules/jsdom/lib/jsdom/utils.js (web.browser)

If you notice problems related to these missing modules, consider running:

  meteor npm install --save canvas   

So I tried to install canvas... and doesn't seem to be working totally fine since the beginning:

> canvas@1.6.2 install /Users/miguel/Proyectos/ProMIR/LMS/node_modules/canvas
> node-gyp rebuild

  SOLINK_MODULE(target) Release/canvas-postbuild.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
  CXX(target) Release/obj.target/canvas/src/Canvas.o
  CXX(target) Release/obj.target/canvas/src/CanvasGradient.o
  CXX(target) Release/obj.target/canvas/src/CanvasPattern.o
  CXX(target) Release/obj.target/canvas/src/CanvasRenderingContext2d.o
  CXX(target) Release/obj.target/canvas/src/color.o
  CXX(target) Release/obj.target/canvas/src/Image.o
  CXX(target) Release/obj.target/canvas/src/ImageData.o
  CXX(target) Release/obj.target/canvas/src/init.o
  CXX(target) Release/obj.target/canvas/src/FontFace.o
  SOLINK_MODULE(target) Release/canvas.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9
LMS@ /Users/miguel/Proyectos/ProMIR/LMS
└── canvas@1.6.2 

Anyway, I try to run the app again, and now this is the warning:

Unable to resolve some modules:

  "../build/Release/canvas" in /Users/miguel/Proyectos/ProMIR/LMS/node_modules/canvas/lib/bindings.js (web.browser)

So when my app is running and I require 'mathjax-node/lib/main.js' (I noticed it's different in develop branch), here's what I get in browser console:

reporters.js?1478101030478:67 Error: Cannot find module './xhr-sync-worker.js'
Error: Cannot find module './xhr-sync-worker.js'
    at Function.require.resolve (install.js:101)
    at meteorInstall.node_modules.jsdom.lib.jsdom.living.xmlhttprequest.js (xmlhttprequest.js:20)
    at fileEvaluate (install.js:153)
    at require (install.js:82)
    at meteorInstall.node_modules.jsdom.lib.jsdom.browser.Window.js (Window.js:16)
    at fileEvaluate (install.js:153)
    at require (install.js:82)
    at meteorInstall.node_modules.jsdom.lib.jsdom.js (jsdom.js:14)
    at fileEvaluate (install.js:153)
    at require (install.js:82)

So I'm stucked here, I just can't get your module dependencies to work along. And I can't understand why npm is trying to install 'canvas' module even If I don't need it (https://www.npmjs.com/package/jsdom doesn't list 'canvas' as a dependency, it's said to be optional).

pkra commented 7 years ago

Sorry to hear that. I don't know meteor much so I'm out of ideas, I'm afraid.

mathjax-node definitely does not need the canvas module for jsdom.

miguelBinpar commented 7 years ago

Well, I'll keep trying on my own and I'll come back here to share the solution if I get it working.

I'm also thinking about using pure javascript plugin, might be easier...

Anyway, thanks a lot for your help. I really appreciate it.

pkra commented 7 years ago

I'm also thinking about using pure javascript plugin, might be easier...

You're not trying to use mathjax-node on the client by any chance? That won't work (that's what MathJax itself does).

miguelBinpar commented 7 years ago

Yeah, that's what I was trying. I thought the node package was also intended to be a module wrapper for the client plugin... My bad.

I'm already working with the plugin so I'm closing this issue. Thanks again for your help.

pkra commented 7 years ago

Ah, that explains the issues then -- sorry for not guessing that sooner.

MathJax currently requires a DOM and this library provides a jsdom wrapper to make it usable on NodeJS. MathJax v3.0 will enable interaction with more modern module systems next year (and allow for non-DOM rendering directly).