解决 vite build打包报错Top-level await is not available in the configured target

一、错误原因
最高层中不让使用 await
二、解决方案
1.引入vite-plugin-top-level-await

npm install vite-plugin-top-level-await -D

2.在vite.config.js配置此插件

import topLevelAwait from 'vite-plugin-top-level-await'

export default defineConfig({
  plugins: [
    topLevelAwait({
      // The export name of top-level await promise for each chunk module
      promiseExportName: '__tla',
      // The function to generate import names of top-level await promise in each chunk module
      promiseImportName: i => `__tla_${i}`
    })
  ]
});

来源:https://www.jianshu.com/p/fb1ad30fd743

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容