0

I am getting the Error: unknown type "tring" ( throw new Error('Unknown type "' + name + '"' + ', math.js (line 751, col 16)) with math.js . The same error arose frommath.min.js . i have downloaded math.js package from repository https://github.com/josdejong/mathjs and extracted to C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\crm\web\js\mathjs\

Error arose by incuding single line to javascript:

var parser = math.parser();

which is from the official example: http://mathjs.org/docs/expressions/parsing.html#parse

There are no other libraries included except jQuery. If i serch through math.js file, i do not find any variable "tring".

This i a symfony project parent template.

C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\crm\src\CrmBundle\Resources\views\basePlotCalc.html.twig

   {% block javascripts %}  
    <script src="{{ asset('js/jquery-2.2.3.min.js') }}"></script>
    <script src="{{ asset('js/mathjs/dist/math.js') }}"></script> 
   {% endblock %}  {# javascripts#}
olga
  • 959
  • 1
  • 15
  • 42
  • 2
    can you show more of your html? like how are you loading the library maybe you load the wrong file.for me it works: https://jsfiddle.net/k8h98dpg/ – Roland Starke Sep 13 '16 at 12:49
  • As you can see here https://jsfiddle.net/myw2L702/ simply adding the library and calling this method yields no errors. You should begin looking elsewhere as Roland has indicated. – Matt Sep 13 '16 at 12:58
  • i have adjusted the quesion. WIll write more in a minute after checkign if i load right file – olga Sep 13 '16 at 17:19
  • Try to log `'sum('+list.toString()+')'` before `math.parse`. – Alex Kudryashev Sep 13 '16 at 17:23
  • `math.eval('a * b', { a: 3, b: 4 } ) ); ` unclosed bracket... – Meirion Hughes Sep 13 '16 at 17:48
  • I load the right file . I checked by adding `console.log('C:\\Bitnami\\wampstack-5.6.20-0\\apache2\\htdocs\\sym\\crm\\web\\js\\mathjs\\dist\\math.js');` on the top. It prints the string. Now i have no errors, except the error that `ReferenceError: parser is not defined` if i use the string `var parser = math.parser(); console.log('It works!', parser.eval('sqrt(3^2 + 4^2)')); ` – olga Sep 13 '16 at 18:47
  • sorry, sometimes when i copy i write instead of copying. Original file has no mistakes. – olga Sep 13 '16 at 19:53
  • Why i am getting the error `parser is not defined` ? using the code `var parse = math.parser(); ` – olga Sep 13 '16 at 19:54
  • It is possible to fix this error by including parser to the assets : . Nevertheless, later pop-ou errors related to `require`, which most probably is a node.js syntax, while i am working with Apache, php and js. – olga Sep 13 '16 at 20:14

2 Answers2

0

Now, after some time, i have found that the error arose because i provide not the string to parse but try to make the string in parse brackets. See examples below. Seems, previously this error remained in the memory of browser and it looked for me that it arose from var parser = math.parser(); which i tried later (I mean first i tried parse ( string expresion), got the error and did not notice, and than i tried parser, and it seems that the error arose from him ).

C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\sym\crm\src\CrmBundle\Resources\views\moinpl\m1i1LoadJs1d.html.twig
        {% block javascripts %}  {{   parent() }}
        <script>
        window.onload = ( function() {

var parser = math.parser(); // now gives error parser is not defined. 

var list = [10, 20, 60]; 
var node = math.parse( 'sum('+list.toString()+')' );  //gives the error error : 'Unknown type "' + name + '"' + ',  math.js (line 751, col 16))`

var tmpstr = 'sum('+list.toString()+')';
var node = math.parse( tmpstr ); // works

/* the rest of relevant code:
    var code = node.compile();       
    var result = code.eval();
    console.log('result ='+ result);        
    console.log('It works!', parser.eval('sqrt(3^2 + 4^2)')); */

math.eval('a * b', { a: 3, b: 4 }  );  //gives the error error : 'Unknown type "' + name + '"' + ',  math.js (line 751, col 16))`
scope = { a: 3, b: 4 }; math.eval(scope); //works


    }); 
    </script>
    {% endblock %}  {# javascripts#}

On the other hand, now than i clean Mozilla cash with Alt+F5 each time i refresh the browser, i get the another error "parser is not defined".

olga
  • 959
  • 1
  • 15
  • 42
0

I hvae found problems like this , is a error : unknown type “ string” ,

resloved method:

edit math.js , use debug mode , find unknown type function... string , and repleace 2 times " "

math.js code like ...

function u(t) { t = t.replace(" ",""); t = t.replace(" ",""); ...

just remove whitespace 2 times