3 Star 0 Fork 0

mirrors_Rich-Harris / vite-top-level-await-repro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

vite-top-level-await-repro

Illustration of issues around use of top-level await in Vite apps: https://github.com/vitejs/vite/issues/5013

Top-level await doesn't work in SSR

Try node run.js. The expectation is that it will load src/index.js (which depends on src/data.js, which includes a top-level await) and run its exported list_fruits function.

Instead, we get an error:

3:45:57 PM [vite] Error when evaluating SSR module src/index.js:
SyntaxError: Cannot use keyword 'await' outside an async function (2:0)
    at Object.pp$5.raise (/path/to/vite-top-level-await-repro/node_modules/vite/dist/node/chunks/dep-36bf480c.js:47485:13)

This means that apps that use Vite for server-side rendering cannot make use of top-level await.

esbuild options are apparently ignored

This one is probably just PEBKAC, but: I would expect npx vite build to build the app successfully, despite the top-level await failing ESBuild's default safari13.1 target check, because the Vite config specifies esbuild: false. For whatever reason, it's not having any effect.

I encountered this while trying to figure out if there's any magic that Vite performs (or could perform) to transpile top-level awaits for environments where it's not natively supported (of which Safari 14 and below is the only one I particularly care about).

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mirrors_Rich-Harris/vite-top-level-await-repro.git
git@gitee.com:mirrors_Rich-Harris/vite-top-level-await-repro.git
mirrors_Rich-Harris
vite-top-level-await-repro
vite-top-level-await-repro
main

搜索帮助