vue3打包踩坑记录 ERROR: Top-level await is not available in the configured target environment (“es2015“)

vue3打包报错 in the configured target environment “es2015“

打包报错如下

在这里插入图片描述

问题所在

因为做动态配置IP及端口,打包后随时改随时生效 ,代码使用了let baseURL = await axios.get(‘./config.json’);在这里插入图片描述

处理办法

1、下载插件

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

2、vite.config.js配置

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

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}`
		})
	],

然后就搞定了。我也是参照了网上其他博主的方法,这里只是做个人项目踩坑记录。物喜勿喷!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值