Aidre Cabrera
Aidre Cabrera

Reputation: 105

When I run my script, it outputs mml2tex is not a function

When I run my code in RunKit, it outputs "TypeError: mml2tex is not a function" in the console.

Here's the link for the code: https://runkit.com/embed/4rnhdcgjrzwl

var mml2tex = require("mml2tex")
const mml = `
    <math xmlns="http://www.w3.org/1998/Math/MathML">
        <msqrt>
            <mn>2</mn>
        </msqrt>
    </math>
`;

const tex = mml2tex(mml);
console.log(tex);

How do I fix this?

Upvotes: 0

Views: 78

Answers (1)

Yash Kumar Verma
Yash Kumar Verma

Reputation: 9630

you need to change the way you are importing the package.

const mml2tex = require('mml2tex').default;
 
const mml = `<math xmlns="http://www.w3.org/1998/Math/MathML">
        <msqrt>
            <mn>2</mn>
        </msqrt>
    </math>
`;
const tex = mml2tex(mml);
console.log(tex);

notice the extra .default when using the commonjs method. more information in this answer: module.exports vs. export default in Node.js and ES6

Upvotes: 0

Related Questions