在开发时,vita打包报错如下:
原因:
ECMAScript 提案 Top-level await 由 Myles Borins 提出,它可以让你在模块的最高层中使用 await 操作符。在这之前,你只能通过在 async 函数或 async generators 中使用 await 操作符。Top-level await 是个新特性,打包不支持此特性。
解决方案:
1.安装vite-plugin-top-level-await插件
yarn add vite-plugin-top-level-await -D
2.vite.config.js中配置
import topLevelAwait from 'vite-plugin-top-level-await' plugins:[ topLevelAwait({ promiseExportName: '__tla', promiseImportName: (i) => `__tla_${i}`, }), ]
然后重新打包就可以了。
- quot environment configured Top-level availablequot environment configured top-level top-level level await environment globalworkeroptions quot pdfjs-dist top-level externally-managed-environment quot environment quot available install connect quot environment difference repository quot configuration sqlserver 39 quot user configure vscode quot locale-collate configuration arguments quot saxparseexception configuration columnnumber