-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Top-level await
is not supported
#72
Comments
Jiti works with CommonJS api (while top level await is an esm-only feature). Support is possible but might be tricky. In the meantime, use a main wrapper: async function main() {
// Move async logic here
}
main().catch(console.error) |
As the world is (very slowly) moving more into esm, are there any plans on having jiti work with top-level await? SST for example uses top-level await to load environment variables into the server. At least currently, trying to inject runtime config in Nuxt 3 using top-level await does not work and throws |
+1 for top-level await support. Tailwind is now using Jiti to load |
We are on it! This feature require a new API from jiti |
Very glad to hear it! Thanks a lot for the follow-up 🤜💥🤛 |
Hi. Thanks for looking into this. Is there any update on progress? |
Looking to work on this; @pi0 it seems to me that the main problem to solve is when a CommonJS module imports an ESM module with top-level await in it, because at that point the synchronous Reading through the code I see that jiti transpiles everything to CJS, why is that? |
Apart from all technical limitations that are beyond this feature for me to explain, sync API is important for jiti and libraries depend on it. ESM support with top level is on the plan but large scale migration is not that easy. |
I assume that the goal is to support esm module importing through |
In jiti v1.12.9 (via nuxt 2.15.8), top-level
await
doesn't seem to be supported, although it is in Node.js v14+.See also https://v8.dev/features/top-level-await
When starting my Nuxt app (with top-level
await
in a server middleware ESM module), I get the following error:The text was updated successfully, but these errors were encountered: