📚 @pt/common-ui 使用常见问题解答
🎮 一、插件安装后,启动应用报错怎么办?
通常会在终端看到如下错误信息:
bash
[vite] server restarted.
X [ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
node_modules/@pt/common-ui/dist/rust_lib-DaUfxFet.js:127:10:
127 │ const o = await e({ "./rust_lib_bg.js": {
╵ ~~~~~
17:36:56 [vite] (client) error while updating dependencies:
Error: Build failed with 1 error:
node_modules/@pt/common-ui/dist/rust_lib-DaUfxFet.js:127:10: ERROR: Top-level await is not available in
the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
at failureErrorWithLog (E:\project\tudou-agent-scp-web\node_modules\esbuild\lib\main.js:1476:15)
at E:\project\tudou-agent-scp-web\node_modules\esbuild\lib\main.js:945:25 at E:\project\tudou-agent-scp-web\node_modules\esbuild\lib\main.js:1354:9 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)🛠️ 解决方案
修改 Vite 配置
在vite.config.ts文件中添加如下配置:jsexport default defineConfig({ esbuild: { target: 'esnext', }, optimizeDeps: { exclude: ['@pt/common-ui'], // 将该依赖排除出 Vite 的依赖预构建 }, build: { target: 'esnext', }, });检查 tsconfig.json 配置
确保tsconfig.json中的target设置为ESNext:json{ // ...其他配置 "target": "ESNext" // ...其他配置 }
二、使用 markdownItPluginFormpage 插件提示错误处理
错误如下
bash
09:13:31 [vite] (client) Pre-transform error: "ESM integration proposal for Wasm" is not supported currently. Use vite-plugin-wasm or other community plugins to handle this. Alternatively, you can use `.wasm?init` or `.wasm?url`. See https://vite.dev/guide/features.html#webassembly for more details.
09:13:32 [vite] Internal server error: "ESM integration proposal for Wasm" is not supported currently. Use vite-plugin-wasm or other community plugins to handle this. Alternatively, you can use `.wasm?init` or `.wasm?url`. See https://vite.dev/guide/features.html#webassembly for more details.
at LoadPluginContext.load (file:///E:/project/tudou-agent-scp-web/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:46030:13)
at EnvironmentPluginContainer.load (file:///E:/project/tudou-agent-scp-web/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:46974:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async loadAndTransform (file:///E:/project/tudou-agent-scp-web/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:40786:22)
at async viteTransformMiddleware (file:///E:/project/tudou-agent-scp-web/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:42296:24)解决方案
✨ 如果按照以上方法操作后仍有问题,欢迎随时反馈!