Error importing from `mathlive/ssr`
Hello, I'm running into some issues importing the static math formulas from mathlive/ssr. I want to use them in a NodeJS app to converts between different math languages.
I'm simply trying to import as
import { convertLatexToAsciiMath } from "mathlive/ssr";
but am getting this fatal error
node:internal/modules/esm/resolve:314
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './ssr' is not defined by "exports" in [local path]/node_modules/mathlive/package.json
at exportsNotFound (node:internal/modules/esm/resolve:314:10)
at packageExportsResolve (node:internal/modules/esm/resolve:605:13)
at resolveExports (node:internal/modules/cjs/loader:638:36)
at Function._findPath (node:internal/modules/cjs/loader:743:31)
at node:internal/modules/cjs/loader:1230:27
at nextResolveSimple ([local path]/node_modules/tsx/dist/register-DCnOAxY2.cjs:3:942)
at [local path]/node_modules/tsx/dist/register-DCnOAxY2.cjs:2:2550
at [local path]/node_modules/tsx/dist/register-DCnOAxY2.cjs:2:1624
at resolveTsPaths ([local path]/node_modules/tsx/dist/register-DCnOAxY2.cjs:3:760)
at [local path]/node_modules/tsx/dist/register-DCnOAxY2.cjs:3:1038 {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v22.13.1
Thank you
P.S.: I realise that this was not necessarily what this package was intended for, but it's still functionality that could/should work, right? 😅
Yes, this should work.
Try
import { convertLatexToAsciiMath } from "mathlive";
instead.
Yes, this should work.
Try
import { convertLatexToAsciiMath } from "mathlive"; instead.
Unfortunately, in a NodeJS environment it doesn't work because of the missing DOM stuff :/ Similar to this one
Issue #1735 has been resolved.
When in a node.js environment, using import "mathlive" should automatically import the correct SSR variant. I don't know why it doesn't work in your case and I would need more information to replicate the problem and investigate.
I've created this small codesandbox here.
When importing from mathlive/ssr, I get this error
Error: Package subpath './ssr' is not defined by "exports" in /project/workspace/node_modules/mathlive/package.json
at exportsNotFound (node:internal/modules/esm/resolve:303:10)
at packageExportsResolve (node:internal/modules/esm/resolve:593:13)
at resolveExports (node:internal/modules/cjs/loader:591:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:668:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/project/workspace/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/project/workspace/index.ts:2:1) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
When importing from mathlive, I get this one
MathLive 0.105.0: this version of the MathLive library is for use in the browser. A subset of the API is available on the server side in the "mathlive-ssr" library. If using server side rendering (with React for example) you may want to do a dynamic import of the MathLive library inside a `useEffect()` call.
/project/workspace/node_modules/mathlive/mathlive.min.js:2
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathLive = {}));})(this, (function (exports) { 'use strict';
^
ReferenceError: HTMLElement is not defined
at /project/workspace/node_modules/mathlive/mathlive.min.js:3116:4191
at /project/workspace/node_modules/mathlive/mathlive.min.js:3124:23634
at /project/workspace/node_modules/mathlive/mathlive.min.js:2:94
at Object.<anonymous> (/project/workspace/node_modules/mathlive/mathlive.min.js:2:294)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Object.require.extensions.<computed> [as .js] (/project/workspace/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
[nodemon] app crashed - waiting for file changes before starting...
Node version is v22.13.1.
Mathlive version is v0.105.0.
I believe this is now fixed.