項(xiàng)目在用vite打包時(shí)報(bào)錯(cuò)
報(bào)錯(cuò)信息:“Top-level await is not available in the configured target environmen“ 翻譯 “頂級(jí)等待在配置的目標(biāo)環(huán)境中不可用”
解決問(wèn)題
- npm安裝vite-plugin-top-level-await插件
npm install vite-plugin-top-level-await -D
- 配置vite.config.js文件
import topLevelAwait from 'vite-plugin-top-level-await'
之后在plugins中添加topLevelAwait方法文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-694832.html
plugins: [
topLevelAwait({
promiseExportName: '__tla',
promiseImportName: i => `__tla_${i}`
})
],
最后重新打包即可文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-694832.html
到了這里,關(guān)于Vite解決報(bào)錯(cuò)(Top-level await is not available in the configured target environment)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!