Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uniapp + vite + ts 在使用 latex 插件时编译报错 #572

Open
chengazhen opened this issue Jan 11, 2024 · 2 comments
Open

uniapp + vite + ts 在使用 latex 插件时编译报错 #572

chengazhen opened this issue Jan 11, 2024 · 2 comments

Comments

@chengazhen
Copy link

chengazhen commented Jan 11, 2024

使用环境

 "devDependencies": {
    "@antfu/eslint-config": "2.6.1",
    "@dcloudio/types": "^3.4.6",
    "@dcloudio/uni-automator": "3.0.0-3081220230817001",
    "@dcloudio/uni-cli-shared": "3.0.0-3081220230817001",
    "@dcloudio/uni-stacktracey": "3.0.0-3081220230817001",
    "@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001",
    "@uni-helper/vite-plugin-uni-components": "^0.0.8",
    "@unocss/transformer-directives": "^0.57.7",
    "@vue/runtime-core": "^3.4.6",
    "@vue/tsconfig": "^0.1.3",
    "eslint": "^8.56.0",
    "husky": "^8.0.3",
    "lint-staged": "^15.2.0",
    "sass": "^1.69.7",
    "sass-loader": "10",
    "typescript": "^4.9.5",
    "unocss": "^0.57.7",
    "unocss-preset-weapp": "^0.56.1",
    "unplugin-auto-import": "^0.16.7",
    "unplugin-vue-components": "^0.25.2",
    "vite": "4.1.4",
    "vue-tsc": "^1.8.27"
  },

问题描述

此处编译为 微信小程序平台时报错, 原因大致定位为vite 编译过程无法正确识别当前的 katex.min.js 文件。代码仓库中的代码阅读过后应该是作者使用工具从 cjs 转换为 es module 的
image

解决方法

在 vite 文档中有指出如何使用 commonjs, 经过尝试也确实可以正常编译。 将 katex.min.js 重命名为 katex.min.cjs , 或者将 katex.min.js 转换为 es 打包的代码。
image

期望

作者是否准备未来适配 vite 文档中的方式

复现方式

只是打包的问题
代码仓库 https://github.com/chengazhen/uniapp-template/tree/demo_latex 页面路径 pages/katex/katex

@jin-yufeng
Copy link
Owner

构建为 uni-app 包的时候会把 module.exports= 替换为 export default 的,应该是符合 esm 格式的,我在 HBuilder X 中使用 vue3 编译也没有报错
这个报错位置 2:93779 具体是哪里,katex.min.js 只有1行才对

@chengazhen
Copy link
Author

我使用的vuelic ,可能跟vite版本也有关系,想问一下,此仓库的 katex.min.js 是不是修改过的文件,并不是最初构建出来的katex.min.js。我通过小程序版的仓库构建后发现和这个文件有差别,文件最后一行并没有export default t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants