前言
在项目中使用pnpm run dev
时,出现了Top-
level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari13" + 2 overrides)
报错。
过程
在网上的方法:
php
export default defineConfig({
build: {
target: 'esnext'
}
})
发现不能解决问题,依旧会报错,先补充一下新的方法:
解决方法
php
// vite.config.js
export default defineConfig({
optimizeDeps: {
esbuildOptions: {
target: 'esnext'
}
},
build: {
target: 'esnext'
},
// more config options ...
})
已成功解决
参考资料
\]([Vite 打包构建报错:Top-level await is not available in the configured... 的异常排查及解决方案 - 掘金](https://juejin.cn/post/7360951254607331337 "https://juejin.cn/post/7360951254607331337")) \[\]([typescript - 在 Vite 中构建我的项目时出错 - 顶级 await 在配置的目标环境中不可用 - Stack Overflow](https://link.juejin.cn?target=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F72618944%2Fget-error-to-build-my-project-in-vite-top-level-await-is-not-available-in-the "https://stackoverflow.com/questions/72618944/get-error-to-build-my-project-in-vite-top-level-await-is-not-available-in-the"))