Cannot use jsroot in next.js (React)

I have a web application using next.js (a React framework)

This is my simple component page.tsx

import { openFile } from 'jsroot';

export default function ExamplePage() {
    let file = openFile('public/myfile.root');
    return (
        <>  </>
    );
}

I get


Module not found: Can't resolve 'gl'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/jsroot/modules/hist/TH2Painter.mjs
./node_modules/jsroot/modules/main.mjs
./src/app/example/page.tsx

I’m sure @linev can help you

Did you try to call npm install gl?

Sure, that is what I was doing, but I wanted to undestand the problem since if I run a node interactive session everything works, e.g.

node

const { openFile } = await import("jsroot");
openfile('myroot.root');

Installing gl works, but then I hit the next dependency

Module not found: Can't resolve 'fflate'

Normally npm install all necessary dependency automatically.

Only if you are using npm install --production flag some extra dependencies will be skipped.

I am installing with npm install jsroot.

Looks like npm does not install “devDependencies” from jsroot any longer.

To use all jsroot functions one need “gl”, “fflate” and several other modules.
Please try to install them “by hand”

“gl” was removed from normal dependencies some time ago because of install problems on several platforms. Meanwhile problem is resolved - may be I need to add it again.

everything works if I resolve the dependencies manually

I will add missing dependency to the next jsroot release 7.7.1

thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.