Problem building MathJax 4.1.1

42 views
Skip to first unread message

Hruodr

unread,
Feb 28, 2026, 12:44:04 PM (10 days ago) Feb 28
to MathJax Users
Hallo!

I wanted to have MathJax with the wiki, tech-notes and forum of fossil-scm,
I think I had success with MathJax3, see:


The problem with MathJax 4 was that at a moment it began to try to search for newcm fonts in the internet and fossil blocks it due to security.  I did not manage to make it search in my local copy. I do not know if I will find such indeterministic behavior with MathJax 3, but till now is working.

Then I tried to build MathJax following


I become warnings after  "pnpm install" and errror after "pnpm -s build-all". I reproduce them below.

Any hint? My knowledge of Java Script is very basic. I am used to build with "make and make install" after configuring, this nodejs story is strange for me. And I do not like smart programs that search in internet without my permission. But I like TeX and want it in my fossil repo.

Thanks for any hint
Rod

Here the warning and errors:

pnpm install

 WARN  12 deprecated subdependencies found: copy-con...@1.0.5, figgy-puddi
n...@3.5.2, fs-write-st...@1.0.10, fsev...@1.2.13, gl...@7.2.3, inflight@1
.0.6, move-con...@1.0.1, resol...@0.2.1, rim...@2.7.1, source-map-resol
v...@0.5.3, source-...@0.4.1, ur...@0.1.0

...

pnpm -s build-all

.... Many errors like: .....

Webpack failed with code 2
Webpacking /mjs/input/tex/extensions/textmacros
[webpack-cli] Invalid configuration object. Webpack has been initialised using a
 configuration object that does not match the API schema.
 - configuration.target should be one of these:
   "web" | "webworker" | "node" | "async-node" | "node-webkit" | "electron-main"
 | "electron-renderer" | "electron-preload" | function
   -> Environment to build for
   Details:
    * configuration.target should be one of these:
      "web" | "webworker" | "node" | "async-node" | "node-webkit" | "electron-ma
in" | "electron-renderer" | "electron-preload"
    * configuration.target should be an instance of function

Webpack failed with code 2



Davide Cervone

unread,
Mar 5, 2026, 5:35:38 PM (4 days ago) Mar 5
to mathja...@googlegroups.com
Rod:

I'm sorry you are having problems with MathJax 4.  While MathJax works best when loaded from a CDN, you can host your own copy.  MathJax v3 had only one font, and it was included in the MathJax node package and GitHub repository; but in MathJax v4, there are several fonts to choose from, and they are made available in their own node packages, which are also hosted on the CDNs that offer MathJax.  Because the fonts in v4 have much greater character coverage than the (single) v3 TeX font, the fonts and their associated data files in v4 are broken into smaller pieces that need to be obtained from the font node package.

MathJax needs to know where to find the fonts and data files it needs, and by default, when MathJax is used in a browser, it looks for the fonts at cdn.jsdelivr.net, as that is a known location that provides the fonts.  If you are hosting your own copy of MathJax, it will still look for the fonts on cdn.jsdelivr.net, but you can configure MathJax to load the fonts from your own site if you want to host the fonts yourself.  That is why you are seeing the requests to cdn.jsdelivr.net.  When you are self-hosting MathJax and its fonts, MathJax doesn't know where you may have put the fonts on your server, so you have to tell it that explicitly using the MathJax configuration object.

To host your own copy of the fonts, see


which includes instructions for how to obtain the fonts, and how to configure MathJax to find them.

If you don't know what the MathJax configuration object is, see


for details.

There is no reason to build MathJax yourself unless you are modifying the MathJax source code, as the MathJax node package already includes all the files that you would get by building it yourself.  

Here the warning and errors:

pnpm install

 WARN  12 deprecated subdependencies found: copy-con...@1.0.5, figgy-puddi
n...@3.5.2, fs-write-st...@1.0.10, fsev...@1.2.13, gl...@7.2.3, inflight@1
.0.6, move-con...@1.0.1, resol...@0.2.1, rim...@2.7.1, source-map-resol
v...@0.5.3, source-...@0.4.1, ur...@0.1.0

Most of these are not dependencies of MathJax or any of its dependents, so I'm confused why you would be getting these, unless you are working in a directory that already has a package.json file in it (or in one of its parent directories) and have not CDed to the MathJax directory before issuing the "pnpm install" command.

pnpm -s build-all

.... Many errors like: .....

Webpack failed with code 2
Webpacking /mjs/input/tex/extensions/textmacros
[webpack-cli] Invalid configuration object. Webpack has been initialised using a
 configuration object that does not match the API schema.
 - configuration.target should be one of these:
   "web" | "webworker" | "node" | "async-node" | "node-webkit" | "electron-main"
 | "electron-renderer" | "electron-preload" | function
   -> Environment to build for
   Details:
    * configuration.target should be one of these:
      "web" | "webworker" | "node" | "async-node" | "node-webkit" | "electron-ma
in" | "electron-renderer" | "electron-preload"
    * configuration.target should be an instance of function

Webpack failed with code 2

What version of webpack are you using?

Given your experience level with javascript (as you describe it), I would not recommend modifying the MathJax code, or trying to rebuild it.

You should be able to use the mathjax@4 node package along with the @mathjax/mathjax-newcm-font@4 font package, provided you configure MathJax to look for the font where you have made it available on your server.

I expect that you should be able to do

mkdir mathjax
cd mathjax
pnpm init
pnpm install mathjax@4
pnpm install @mathjax/mathjax-newcm-font@4

and then move the node_modules/mathjax and node_modules/@mathjax/mathjax-newcm-font directories to somewhere that they will be available to your server.  Then use

<script>
MathJax = {
  output: {
    fontPath: '<path-to-mathjax-newcm-font>',
  }
};
</script>
<script src="<path-to-mathjax>/tex-chtml.js"></script>

in your HTML file to configure and load MathJax's tex-chtml.js component (or substitute whichever one you need).  Of course you replace the "<path-to-...>" markers with the actual URL to the locations on your server.

That should do it.

Davide

Hruodr

unread,
Mar 7, 2026, 8:16:20 AM (3 days ago) Mar 7
to MathJax Users
Davide, thanks for the info! 

I will keep it for the time I change to MathJax4.  MathJax 3 is working well for my purpose and MathJax4 is too new.

About: "If you are hosting your own copy of MathJax, it will still look for the fonts on cdn.jsdelivr.net".
If I am hosting my own copy of MathJax, it should be clear that I want to run it locally and I do not want links to outside.
It is in my opinion a little flaw in the design with consequences that one perhaps not even note, namely that MathJax
is doing something that one explicitly does not want and taking fonts from outside, or that one notes and causes troubles, 
for example fossil blocking that internet connections for security reasons.

I normally build programs, keep some in repositories, even if I do not change them. This gives also an impression of the 
quality of the program,  the dependencies and their amount, if it compiles clean or with a lot of warnings, also the troubles 
compiling says something. Unfortunately I have almost no experience with node or javascript and not even know what
webpack is.

I had a node repository for an older version, all was much simpler.

In any case, I thank you for your answer.

Rod

Davide Cervone

unread,
Mar 7, 2026, 5:25:13 PM (2 days ago) Mar 7
to mathja...@googlegroups.com
About: "If you are hosting your own copy of MathJax, it will still look for the fonts on cdn.jsdelivr.net".
If I am hosting my own copy of MathJax, it should be clear that I want to run it locally and I do not want links to outside.
It is in my opinion a little flaw in the design with consequences that one perhaps not even note, namely that MathJax
is doing something that one explicitly does not want and taking fonts from outside, or that one notes and causes troubles, 
for example fossil blocking that internet connections for security reasons.

I understand your point, but there are a couple of things to consider.  First, MathJax has no idea whether you are self hosting or loading to from a CDN or other service (there are half a dozen or more CDNs it could come from, for example).  Second, because there are 11 fonts to choose from (and that is likely to grow in the future), and they can be fairly large, the main MathJax package (and GitHub site) don't include the fonts directly – they are distributed through separate npm packages so that you can load the one(s) you want without having to have all the rest – but in order for MathJax to be able to access the font, it needs to know the URL where it resides.  If you host the font you want on your own site, MathJax has no idea where you have put the fonts, as it doesn't know the structure of your website or file system, so there is no way for it to access the fonts without your telling it where they are.  By default, MathJax will access the fonts via cdn.jsdelivr.net because that is an address where it can be sure the fonts are available.   You can override that via the fontPath configuration option, as documented in one of the links I sent you earlier, so if you host your own fonts, that is what you need to use to tell MathJax where you have put them.

I normally build programs, keep some in repositories, even if I do not change them. This gives also an impression of the 
quality of the program,  the dependencies and their amount, if it compiles clean or with a lot of warnings, also the troubles 
compiling says something. Unfortunately I have almost no experience with node or javascript and not even know what
webpack is.

Well, I am not able to reproduce the problem you are having (and have not hear of such problems from others).  You don't give much detail about your environment (e.g., the OS you are using, the versions of node and webpack that you are using, etc.), so there isn't much I can tell you other than that the messages you included in your original message suggest that the pnpm install command was installing things other than just MathJax (as the packages it complained about are not used by MathJax or its dependencies).  You might look at the package.json file in the directory where you issued the pnpm install and check the file looks like it is this one:


As for the webpack errors, these seem strange to me, as the complaint seems to be about configuration.target not being one of the accepted values.  This could be a version problem.  You should check the versions of node and webpack using

pnpm webpack --version

Node's current vision is 25, and you should have webpack 5.105.2 from the MathJax installation.  If you do

pnpm list

you should get something that includes

dependencies:
@mathjax/mathjax-newcm-font 4.1.1
mhchemparser 4.2.1
mj-context-menu 1.0.0
speech-rule-engine 5.0.0-beta.6

devDependencies:
@eslint/js 9.39.2             eslint-plugin-jsdoc 62.5.5    terser-webpack-plugin 5.3.16  webpack-cli 6.0.1             
@xmldom/xmldom 0.8.11         eslint-plugin-prettier 5.5.5  typedoc 0.28.17               wicked-good-xpath 1.3.0       
copyfiles 2.4.1               husky 9.1.7                   typescript 5.9.3              xslt3 2.7.0                   
diff 8.0.3                    lint-staged 16.2.7            typescript-eslint 8.56.0      
eslint 9.39.2                 prettier 3.8.1                typescript-tools 0.3.1        
eslint-formatter-unix 9.0.1   rimraf 6.1.3                  webpack 5.105.2     

with no additional packages.

If these aren't what you are seeing, then there is a problem with your installation.

Davide


-- 
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mathjax-users/1147acdd-841b-4622-b238-9cee214573d8n%40googlegroups.com.

Hruodr

unread,
Mar 8, 2026, 2:07:14 PM (2 days ago) Mar 8
to MathJax Users


Davide Cervone schrieb am Samstag, 7. März 2026 um 22:25:13 UTC:

Thanks, here some info:

You don't give much detail about your environment (e.g., the OS you are using, the versions of node and webpack that you are using, etc.),

# uname -a
FreeBSD fbsd.local 14.3-RELEASE-p3 FreeBSD 14.3-RELEASE-p3 GENERIC amd64

# node -v
v24.7.0

You might look at the package.json file in the directory where you issued the pnpm install and check the file looks like it is this one:

The file is there. What should I see?

As for the webpack errors, these seem strange to me, as the complaint seems to be about configuration.target not being one of the accepted values.  This could be a version problem.  You should check the versions of node and webpack using

pnpm webpack --version

 # pnpm webpack --version
webpack: 4.47.0
webpack-cli: 4.10.0
webpack-dev-server not installed

 
Node's current vision is 25, and you should have webpack 5.105.2 from the MathJax installation.  If you do

pnpm list

 # pnpm list
Legend: production dependency, optional only, dev only

@mathjax/s...@4.1.1 /usr/opt/GRepo/MathJax-src

│   dependencies:
├── @mathjax/mathjax-n...@4.1.1
├── mhchem...@4.2.1
├── mj-cont...@1.0.0
├── speech-ru...@5.0.0-beta.6

│   devDependencies:
├── @eslint/j...@9.39.3
├── @xmldom/xml...@0.8.11
├── copy...@2.4.1
├── di...@8.0.3
├── esl...@9.39.3
├── eslint-for...@9.0.1
├── eslint-pl...@62.7.1
├── eslint-plug...@5.5.5
├── hu...@9.1.7
├── lint-...@16.3.0
├── pret...@3.8.1
├── rim...@6.1.3
├── terser-web...@5.3.16
├── typ...@0.28.17
├── types...@5.9.3
├── typescri...@8.56.1
├── typescri...@0.3.1
├── web...@4.47.0
├── webpa...@4.10.0
├── wicked-g...@1.3.0
└── xs...@2.7.0

25 packages



Davide Cervone

unread,
Mar 9, 2026, 7:53:49 AM (21 hours ago) Mar 9
to mathja...@googlegroups.com
Thanks, here some info:

Thank you, that is all very helpful.


You might look at the package.json file in the directory where you issued the pnpm install and check the file looks like it is this one:

The file is there. What should I see?

I had meant for you to compare the contents of the package.json file you have to the content shown at the link above.  That is no longer needed, as the other data you provide makes that unnecessary.

As for the webpack errors, these seem strange to me, as the complaint seems to be about configuration.target not being one of the accepted values.  This could be a version problem.  You should check the versions of node and webpack using

pnpm webpack --version

 # pnpm webpack --version
webpack: 4.47.0
webpack-cli: 4.10.0
webpack-dev-server not installed

This is the problem.  The webpack version is a major version out of date (see below);
This all looks good EXCEPT for the webpack and webpack-cli versions, which are out of date.  The package.json file indicates that these should be 5.105.2 and 6.0.1, as shown in these lines:


but you have versions 4.47.0 and 4.10.0.  I'm not sure why that would be the case, as the package.json file and the pnpm-lock.yaml file are supposed to guarantee the correct versions are installed.  Did you do an npm install or pnpm install of either of these by hand?

Can you do

git status

to check if there have been any local changes made to these files (and that you are on the master branch of the git repository)?

The installation of web...@4.47.0 is the source of both the install warnings that you got, and the failures during the build process.  You need to use webpack version 5, as the package.json indicates.  You might try installing the correct versions explicitly:

pnpm install web...@5.105.2
pnpm install webpa...@6.0.1

That should install without warnings (once you get both installed), and should allow the build process to succeed.

Again, I'm not sure how you got those old versions, while everything else is the correct version.  But that is definitely the source of the troubles you are having.

Davide





--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.

Hruodr

unread,
Mar 9, 2026, 12:48:02 PM (16 hours ago) Mar 9
to MathJax Users


Davide Cervone schrieb am Montag, 9. März 2026 um 11:53:49 UTC:
....

Thanks!

Quite frustrated I did: 

rm -rf whole-repository-with-checkout-and-everything-and-forget-everything
cd MathJax-src
git checkout 4.1.1
pnpm install
pnpm -s build-all

Then worked, very clean, but what I got? And what I do now with it?

In any other piece of software there is a file README and a file INSTALL with
enough info for building and making the whole work.

I had mathjax 2 embedded in fossil, I have now mathjax3 doing it with:
mkdir MathJax
cd MathJax
npm install mathjax-full

But what I do now with mathjax 4?!

Must I clone a repo for fonts and build something?
I see in the checkout with what I just built:

node_modules/@mathjax/mathjax-newcm-font/

Are that the fonts? What is what there?

A simple answer could be, I should read the web pages, but exactly that was
the reason that I had the false webpack: there are a lot of different instructions,
I think I did before first something with npm, then I did  as root, with a lot of
distrust and bad feeling: "npm install -g pnpm".

All this is a different ecosystem than the one is used with normal UNIXoids.

Regards
Rod.

Davide Cervone

unread,
Mar 9, 2026, 6:41:49 PM (10 hours ago) Mar 9
to mathja...@googlegroups.com
Rod:

I did: 

rm -rf whole-repository-with-checkout-and-everything-and-forget-everything
cd MathJax-src
git checkout 4.1.1
pnpm install
pnpm -s build-all

Your original installation seemed to be corrupted, so this was a good approach to correcting the situation.

Then worked, very clean,

I'm glad it worked for you.

but what I got?

What you did was to transpile the Typescript source files into plain javascript files in two different forms:  the modern ES6 versions in the "mjs" directory, and the older ES5 versions in the "cjs" directory.  The former are webpacked into the "bundle" directory to form the components needed to use MathJax in a web page.  The latter are the files that you would have obtained via "pnpm install mathjax@4" while "pnpm install @mathjax/src@4" would have gotten you essentially the files you have created by the build process.  The "mjs" and "cjs" files are the ones you would use if you were making a node application that called on the MathJax modules directly (rather than through the MathJax Components framework).

And what I do now with it?

I don't know anything about fossil, but I assume you need to move the contents of the "bundle" directory to some place that fossil can access it, and then configure fossil to load the MathJax component that you want to use from there.  You will also need to make sure the fossil pages have the needed configuration to tell them where to locate the fonts (see below).

In any other piece of software there is a file README and a file INSTALL with
enough info for building and making the whole work.

There is a README.md file in the repository that you downloaded, and it is displayed at the MathJax GitHub site (below the directory listing).  It tells you how to use MathJax in a web site using the CDN (the usual approach) or in a server-side or command-line node application (the other main use for MathJax).  It also has pointers to the main documentation and to the web and node example repositories.  The documentation includes a section on hosting your own copy of MathJax, which tells you about moving the files to a location where your server can access it, how to obtain the needed font files, and how to configure MathJax to use them.  You cited that document in your initial message, but I'm not sure you read all of it, because it has a section on the fonts (I referred you to that earlier).

I had mathjax 2 embedded in fossil, I have now mathjax3 doing it with:
mkdir MathJax
cd MathJax
npm install mathjax-full

But what I do now with mathjax 4?!

You would use "npm install @mathjax/src@4" to replace "npm install mathjax-full", or better, just "npm install mathjax@4" to get a smaller installation of just the bundled files without all the source code and other pieces that you aren't going to need.  Then install the font you plan to use (see below), and then include the needed configuration in your fossil pages and link to the MathJax component you want to use just as you did with v3, but using the URL to for the location of that file in the directory where you placed the MathJax files.  If your original was making calls to "node_modules/mathjax-full/es5/tex-chtml.js" for example, then you would use "node_modules/@mathjax/src/bundle/tex-chtml.js" instead (or "node_modules/mathjax/tex-chtml.js" if you had installed mathjax@4 rather than @mathJax/src@4).

Must I clone a repo for fonts and build something?

You do need to have one of the fonts available to your fossil page, yes.  But these are currently only available as npm packages (the font building tools are not yet ready for public consumption, so only the final npm packages are available ad this point).

I see in the checkout with what I just built:

node_modules/@mathjax/mathjax-newcm-font/

Yes, that would be the default font.  You need to make that available to the fossil page, and set MathJax's "fontPath" configuration option to point to where it is on your server.  That could be to "node_modules/@mathjax/mathjax-newcm-font" if you are serving the files directly out of the node_modules directory.

Are that the fonts? What is what there?

Yes, that is the font.

A simple answer could be, I should read the web pages,

Yes, the page


includes a section on obtaining the needed fonts and how to configure MathJax to use them:


An example configuration is given in that section.

but exactly that was the reason that I had the false webpack: there are a lot of different instructions,

There are a lot of different ways that MathJax can be used, so there are instructions for using it in a web page, for using it in node applications, and for self-hosting a copy yourself.  I'm sorry these were confusing to you.

I think I did before first something with npm, then I did  as root, with a lot of
distrust and bad feeling: "npm install -g pnpm".

In order to build MathJax yourself, you do need to have pnpm installed, yes.  To use either the mathjax@4 or @mathjax/src@4 node packages, you don't need pnpm.  But you have chosen to take the more difficult and unnecessary route of building MathJax yourself.


All this is a different ecosystem than the one is used with normal UNIXoids.

MathJax is not a unix application, it is a javascript library that can be used in any environment that can run javascript.  That means web browsers, or node applications, or some ebook readers, or some applications that use WebView components, and so on.  That can be on Windows, unix, or any operating system that can run a browser or a node application.  Because MathJax is part of the javascript/node ecosystem, it uses the package managers, like npm and pnpm, associated with that environment.  It is set up like all npm packages, so that "npm install" will install the needed files and dependencies, without the need to build it yourself.  You took the harder route of building your own copy, which is fine, but takes more knowledge.

Note that even for unix systems, most software is now distributed using package managers like "apt", which handle the installation of dependencies and the building of packages when needed.  Most people don't build the software by hand any more, even on unix.  

Davide


Reply all
Reply to author
Forward
0 new messages