michael-brade / LaTeX.js

JavaScript LaTeX to HTML5 translator
https://latex.js.org
MIT License
770 stars 58 forks source link

'ERR_REQUIRE_ESM' when using CLI #149

Open catEvasion opened 6 months ago

catEvasion commented 6 months ago

I kept encountering an issue with the CLI. An error occurred: 'ERR_REQUIRE_ESM'.

I managed to create a workaround by avoiding the CLI and using the library instead. I set up a node project in a repository to convert all documents in a folder.

The error can be reproduced by cloning the project and running npm run cli.

https://gitlab.com/catEvasion/latex.js-setup

Marco-DG commented 3 days ago

I have same issue.

This is the full error:

/usr/local/lib/node_modules/latex.js/bin/latex.js:3
ref$ = require('svgdom'), createHTMLWindow = ref$.createHTMLWindow, config = ref$.config;
       ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/latex.js/node_modules/svgdom/main-module.js from /usr/local/lib/node_modules/latex.js/bin/latex.js not supported.
Instead change the require of main-module.js in /usr/local/lib/node_modules/latex.js/bin/latex.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/usr/local/lib/node_modules/latex.js/bin/latex.js:3:8) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.18.2