【问题标题】:When I run my script, it outputs mml2tex is not a function当我运行我的脚本时,它输出 mml2tex is not a function
【发布时间】:2021-12-29 08:07:48
【问题描述】:

当我在 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);

我该如何解决这个问题?

【问题讨论】:

    标签: node.js npm npm-install npm-scripts runkit


    【解决方案1】:

    您需要更改导入包的方式。

    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 and ES6

    【讨论】:

      猜你喜欢
      • 2021-05-28
      • 2019-06-06
      • 2022-07-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 2019-11-13
      相关资源
      最近更新 更多