Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems cloning MathJax-src repo #2358

Closed
ghost opened this issue Feb 26, 2020 · 4 comments
Closed

Problems cloning MathJax-src repo #2358

ghost opened this issue Feb 26, 2020 · 4 comments
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Not Needed v3
Milestone

Comments

@ghost
Copy link

ghost commented Feb 26, 2020

I am looking to clone the MathJax source repo and I am running into errors when compiling with TypeScript.

I ran npm install, npm update and tried updating Node and npm, but I still get the following errors when trying to run npm run install:

ts/a11y/sre-node.ts:25:15 - error TS2451: Cannot redeclare block-scoped variable 'require'.

25 declare const require: (name: string) => any;
~~~~~~~

../node_modules/@types/node/globals.d.ts:222:13
222 declare var require: NodeRequire;
~~~~~~~
'require' was also declared here.

ts/a11y/sre-node.ts:29:15 - error TS2451: Cannot redeclare block-scoped variable 'global'.

29 declare const global: any;
~~~~~~

../node_modules/@types/node/globals.d.ts:167:13
167 declare var global: NodeJS.Global;
~~~~~~
'global' was also declared here.

../node_modules/@types/node/globals.d.ts:167:13 - error TS2451: Cannot redeclare block-scoped variable 'global'.

167 declare var global: NodeJS.Global;
~~~~~~

ts/a11y/sre-node.ts:29:15
29 declare const global: any;
~~~~~~
'global' was also declared here.

../node_modules/@types/node/globals.d.ts:222:13 - error TS2451: Cannot redeclare block-scoped variable 'require'.

222 declare var require: NodeRequire;
~~~~~~~

ts/a11y/sre-node.ts:25:15
25 declare const require: (name: string) => any;
~~~~~~~
'require' was also declared here.

Found 4 errors.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! mathjax-full@3.0.1 compile: npx tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the mathjax-full@3.0.1 compile script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The log file:
2020-02-26T21_05_03_551Z-debug.log

Since I believe that the current commit should most likely compile, I think I must have something wrong with my versions of TypeScript or whatever, but I already checked it using npx tsc -v and it was the same as listed in the devDependencies.

I would really appreciate some help here, since I am actually really keen on getting into MathJax and extending it for my purpose.

@dpvc
Copy link
Member

dpvc commented Feb 28, 2020

OK, I figured it out. According to the tsconfig documentation:

By default all visible “@types” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within ./node_modules/@types/, ../node_modules/@types/, ../../node_modules/@types/, and so on.

The solution is to add

"typeRoots" : ["./typings"]

to the compilerOptions list in the tsconfig.json file in the MathJax-src clone. That will prevent those other files from being included. I'll make a pull request to change the tsconfig.json file accordingly.

@dpvc
Copy link
Member

dpvc commented Feb 28, 2020

I've made a pull request for the change in the tsconfig.json file.

Note, however, that unless you are planning to make pull requests to fix issues in MathJax, you might be better to use the mathjax-full npm package instead, which already includes the compiled versions of the .ts files. You should be able to subclass the existing MathJax classes and use those in most cases rather than modifying the core MathJax code itself.

@ghost
Copy link
Author

ghost commented Feb 29, 2020

Thanks a lot for the help. But I have a question: Why is it advised to use the npm package instead? And since I don't yet know whether I will have to edit the existing MathJax classes, shouldn't I use the git clone to make sure I am not "limited" in what I can do?

@dpvc
Copy link
Member

dpvc commented Mar 2, 2020

Why is it advised to use the npm package instead?

Mostly because it already includes the compiled files, but also because it makes it easier to include MathJax in your package.json than having to clone the repo by hand.

And since I don't yet know whether I will have to edit the existing MathJax classes, shouldn't I use the git clone to make sure I am not "limited" in what I can do?

As I mention above, the mathjax-full package includes the original typescript files that are in the Git repository, so you are not limited in what you can do, but you are right that if you are planning to modify the MathJax files themselves, you probably do want to use the Git repository so that it is easier to update as new versions come out.

But again, I don't recommend changing the base MathJax code unless you are planning to make pull requests back to the MathJax source repository. Instead, you should subclass the objects you plan to change, make the changes in your subclass, and use the subclasses instead of the base MathJax classes. It is possible to substitute your own classes for most of the originals (though there are some places where that is more difficult to do). For example, if you want to change the FindTeX class that locates the TeX delimiters in the document, you can subclass the original and pass your new class to the TeX input jax in its options list. Many of the key classes can be specified in that way.

@dpvc dpvc added this to the 3.0.2 milestone Mar 5, 2020
dpvc added a commit to mathjax/MathJax-src that referenced this issue Mar 30, 2020
Prevent reading node_modules/@types from containing directories.  (mathjax/MathJax#2358)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Mar 30, 2020
@dpvc dpvc added the Fixed label Apr 10, 2020
@dpvc dpvc closed this as completed Apr 10, 2020
@dpvc dpvc removed the Merged Merged into develop branch label Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Not Needed v3
Projects
None yet
Development

No branches or pull requests

1 participant