簡體   English   中英

當我運行我的腳本時,它輸出 mml2tex is not a function

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

當我在 RunKit 中運行我的代碼時,它會在控制台中輸出“TypeError: mml2tex is not a function”。

這是代碼的鏈接: 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);

我該如何解決?

您需要更改導入 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);

注意使用 commonjs 方法時額外的.default 此答案中的更多信息: module.exports vs. export default in Node.js 和 ES6

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM