Can't install via npm for client (browser) applications (via vite)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Issue Summary
I need to turn a TeX string to a SVG file in a svelte 5 application (vite, in browser). I was expecting to be able to simply do as documented:
npm install mathjax@4
(I also tried with mathjax-full)
and then
import MathJax from 'mathjax';
await MathJax.init({
loader: {load: ['input/tex', 'output/svg']}
});
const svg = await MathJax.tex2svgPromise('\\frac{1}{x^2-1}', {display: true});
console.log(MathJax.startup.adaptor.serializeXML(svg));
But if I do that it fails saying that global is undefined. It seems like the issue is that this is actually for node applications, but I don't want to rely on a CDN, I really want to use npm + vite to package my app & get typescript support. Is it possible? If yes, doc should be improved, if not… well it should be solved as I guess I'm not the only person interested by this feature.
Steps to Reproduce:
- Create a basic sveltekit app via
npx sv create my-app, enable typescript - Run
npm install mathjax@4 - In the
src/route/+page.svelteadd the above code (and enable experimental await support)
Technical details:
- MathJax Version: 4.1.2
- Client OS: NixOs
- Browser: Firefox, but not relevant
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure in a SvelteKit app using src/route/+page.svelte, npm install mathjax@4, and the documented MathJax initialization. Start by checking how the mathjax and mathjax-full packages are bundled by Vite for browser use and where the global reference occurs. Done means the documented npm setup works in the browser with TypeScript, or the documentation clearly explains the supported approach and limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript, vite
- Domain
- build-system, frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100