vite打包记录

error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided

解决办法

// 修改package.json
 "build": "vue-tsc --noEmit --skipLibCheck && vite build",

ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")

主要是因为顶级await导致的

解决办法

1. 安装vite-plugin-top-level-await包(网上的,我用起来没用)

npm install vite-plugin-top-level-await -D
// vue.config.ts中
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}`
    })
  ]
});

2. 老老实实用async+await

posted @ 2022-10-17 17:25  枫子_dan  阅读(465)  评论(0编辑  收藏  举报