首页 > 解决方案 > 通过 npm / index.html 将 tex2max.js 导入 Angular 项目

问题描述

当我尝试使用导入时tex2maxdeclare var tex2max: any;我得到一个ReferenceError: tex2max is not defined. 但这不会发生在其他 npm 包中。我尝试通过安装 npm 包并通过 index.html 中的脚本标记来绑定脚本,但无济于事。

这是源代码的CDN文件:

https://unpkg.com/tex2max@1.3.0/lib/tex2max.js

标签: javascriptangularnpmimport

解决方案


如果项目作者稍微更正了他们的包,你可以这样做:

import TeX2Max from 'tex2max';

但这以错误告终[编辑:在 stackblitz 上]

Error in /turbo_modules/tex2max@1.3.0/lib/tex2max.js (13:28806)
Cannot assign to read only property 'exports' of object '[object Object]'

最好的选择是向作者提出问题。

Stackblitz 示例


推荐阅读