简体   繁体   English

当我运行我的脚本时,它输出 mml2tex is not a function

[英]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.

相关问题 当我退出我的 Node 应用程序时,我可以运行 function 吗? - Can I run a function when I quit my Node App? 我可以在Pi上运行脚本并在关闭SSH时使其继续运行吗? - Can I run a script on my Pi and keep it running when I close SSH? 我的 deploycommands.js 文件在我使用脚本时没有运行,当我手动运行它时抛出错误 - My deploycommands.js file is not running when I use a script and throwing an error when I run it manually 当我运行我的 `node file.js 1 23 44` 脚本时,它不会打印任何东西 - when I run my `node file.js 1 23 44` script, it doesn't prinout anything 新的Date()何时在我的函数中运行? - When will new Date() be run in my function? 我可以将node.js脚本输出管道输入`less`而不输入`| 跑的时候少吗? - Can I pipe my node.js script output in to `less` without typing `| less` when run? 我在节点后端运行 npm run dev 时出现问题 - Problem when i run npm run dev in my node backend 当我运行为移动网站(Angular)编写的量角器脚本时,Chrome浏览器和模拟器都自动关闭 - Both Chrome & emulator is closing automatically when I run my protractor script which I wrote for mobile Site(Angular) TypeError: puppeteer.use(...) 在尝试运行我的代码时不是 function - TypeError: puppeteer.use(...) is not a function when trying to run my code 我应该使用工作进程还是子进程来运行我的 function? - Should I use worker or child processes to run my function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM