Vite解决报错(Top-level await is not available in the configured target environment)
•
前端

项目在用vite打包时报错
报错信息:“Top-level await is not available in the configured target environmen“ 翻译 “顶级等待在配置的目标环境中不可用”
解决问题
- npm安装vite-plugin-top-level-await插件
npm install vite-plugin-top-level-await -D
- 配置vite.config.js文件
import topLevelAwait from 'vite-plugin-top-level-await'
之后在plugins中添加topLevelAwait方法
plugins: [
topLevelAwait({
promiseExportName: '__tla',
promiseImportName: i => `__tla_${i}`
})
],
最后重新打包即可

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/6a56c59f23.html
