[英]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.当我在 RunKit 中运行我的代码时,它会在控制台中输出“TypeError: mml2tex is not a function”。
Here's the link for the code: https://runkit.com/embed/4rnhdcgjrzwl这是代码的链接: 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?我该如何解决?
you need to change the way you are importing the package.您需要更改导入 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.注意使用 commonjs 方法时额外的
.default
。 more information in this answer: module.exports vs. export default in Node.js and ES6此答案中的更多信息: module.exports vs. export default in Node.js 和 ES6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.