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

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

项目在用vite打包时报错
报错信息:“Top-level await is not available in the configured target environmen“ 翻译 “顶级等待在配置的目标环境中不可用”

解决问题

  1. npm安装vite-plugin-top-level-await插件
javascript">npm install vite-plugin-top-level-await -D
  1. 配置vite.config.js文件
import topLevelAwait from 'vite-plugin-top-level-await'

之后在plugins中添加topLevelAwait方法

plugins: [
    topLevelAwait({
      promiseExportName: '__tla',
      promiseImportName: i => `__tla_${i}`
    })
  ],

最后重新打包即可

转载请说明出处内容投诉
CSS教程_站长资源网 » Vite解决报错(Top-level await is not available in the configured target environment)

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买