Angular-cli: Problem installing an external script and referencing a variable from it globally (MathJax)

Created on 2 Apr 2017  路  5Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Output from: ng --version:
@angular/cli: 1.0.0
node: 7.2.1
os: win32 x64
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1

OS:
Windows 10.

Repro steps.

I previously set yarn as my default package manager.

I started the project with
ng new math-bug

I installed dependencies

yarn add express body-parser mathjax mongoose
yarn add @types\mathjax --dev

I modified the file .angular-cli.json adding the following to the scripts array (previously empty).

"../node_modules/mathjax/MathJax.js"

I added a component to my project that uses the line:
"MathJax.Hub.Queue([ "Typeset", MathJax.Hub, this.id]);"

The log given by the failure.

When I build my project I get the error:
ERROR in C:/Users/Pat/ProgrammingProjects/math-bug/src/app/latex/latex.component.ts (23,9): Cannot find name 'MathJax'.
C:/Users/Pat/ProgrammingProjects/math-bug/src/app/latex/latex.component.ts (23,40): Cannot find name 'MathJax'.

ERROR in C:/Users/Pat/ProgrammingProjects/math-bug/src/app/latex/latex.component.ts (23,9): Cannot find name 'MathJax'.
C:/Users/Pat/ProgrammingProjects/math-bug/src/app/latex/latex.component.ts (23,40): Cannot find name 'MathJax'.

Desired functionality.

I would like to be able to use MathJax on my project. I previously had an Angular 2 project that used systemjs where this was not a problem. I believe I followed all the instructions for global library installation as described here, but it's possible I'm misunderstanding something.

Mention any other details that might be useful.

I built a repo that demonstrated what's happening. It can be seen here

Most helpful comment

Try adding "mathjax" to the types array in src/tsconfig.app.json. I had a similar error and that fixed it for me.

All 5 comments

i cloned your repo trying to get this running, i added this line to LatextComponent:

import * as MathJax from 'mathjax/MathJax';

the error doesn't show any more, but it shows another error, that it failed to fetch MathMenu and MathZoom, i will keep trying and let you know if anything came up.

it worth mentioning that i've tried:"

import { MathJax } from 'mathjax';

but this error showed up:

File 'math-bug/node_modules/@types/mathjax/index.d.ts' is not a module.'

Try adding "mathjax" to the types array in src/tsconfig.app.json. I had a similar error and that fixed it for me.

@isaacplmann Thanks! That fixed it for me.

Closing as answered by @isaacplmann, cheers!

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MateenKadwaikar picture MateenKadwaikar  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

brtnshrdr picture brtnshrdr  路  3Comments

5amfung picture 5amfung  路  3Comments

hareeshav picture hareeshav  路  3Comments