BertrandBev / eigen-js

⚡ Eigen-js is a port of the Eigen C++ linear algebra library
https://bertrandbev.github.io/eigen-js/#/
92 stars 15 forks source link

Is this supposed to work on Node.js? #58

Closed recidive closed 1 year ago

recidive commented 1 year ago

I'm trying to run eigen-js in Node.js and I'm getting this error when instantiating a new Matrix:

TypeError: eigen_1.default.Matrix is not a constructor

Is this supposed to work on Node.js?

BertrandBev commented 1 year ago

For sure! In a new folder, create a simple package.json file containing

{ "dependencies": { "eigen": "^0.2.2" } }

Create a file named test.mjs containing

` // test.mjs import eig from 'eigen';

(async () => { await eig.ready; let M = new eig.Matrix([[1, 2], [3, 4]]); M.print("M"); M = M.inverse(); M.print("Minv"); eig.GC.flush(); })(); `

Now run yarn in that folder to install dependencies, and execute the test using node test.mjs

recidive commented 1 year ago

Yes, this worked now, but sometimes it breaks with the error TypeError: eigen_1.default.Matrix is not a constructor. I got this intermittently in an Observable notebook.

Maybe this is something related to asynchronous loading of the wasm?

BertrandBev commented 1 year ago

Ah, I never tried it in that context. Not sure how Observable handles package loading...

recidive commented 1 year ago

I'm not saying this is just on Observable but in both contexts, this is an intermittent error that needs some debugging, maybe using async import() in typescript helps.