我试着用vite来构建我的项目,
我的项目- https://github.com/yakovcohen4/starbucks-openlayers
我运行npm run dev和所有的工作。
但是当我跑去构建它时,我会得到一个错误。
错误消息:Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
我试图获取一个数据,并认为这里是问题链接(行22+23) - https://github.com/yakovcohen4/starbucks-openlayers/blob/main/starbucks-project/src/main.ts
const shopsData = await fetchStarbucksShops();
如果有人遇到这个诅咒,我很乐意帮忙。
发布于 2022-06-16 12:01:25
首先,检查这个;https://github.com/vitejs/vite/issues/6985。如果您找不到答案,请尝试创建一个大的fat异步函数,该函数自己执行以降低await的级别;
(async () => {
export const shopsData: shopType[] = await fetchStarbucksShops();
export const countryGeoData: countryGeoDataType = await fetchGeoJsonCountry();
.
.
.
.
.
})();可能不起作用。您应该避免顶层等待,无论是在async函数中使用async,还是使用.then()。
https://stackoverflow.com/questions/72618944
复制相似问题