繁体   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