-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
vite6 [commonjs--resolver] node_modules/testb/a.js (1:6): await isn't allowed in non-async function #18850
Comments
It doesn't work with Vite v5 too. I don't think this should work because top-level await cannot be used in CJS (nodejs/node#21267). |
Have you tried the build mode?
…---- Replied Message ----
| From | ***@***.***> |
| Date | 12/02/2024 09:28 |
| To | vitejs/vite ***@***.***> |
| Cc | zhn ***@***.***>,
Author ***@***.***> |
| Subject | Re: [vitejs/vite] vite6 [commonjs--resolver] node_modules/testb/a.js (1:6): await isn't allowed in non-async function (Issue #18850) |
It doesn't work with Vite v5 too.
https://stackblitz.com/edit/github-441yb3?file=package.json&terminal=build
I don't think this should work because top-level await cannot be used in CJS (nodejs/node#21267).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Yes, I have. |
I don't have a computer with me right now. I'll check it tonight
…---- Replied Message ----
| From | ***@***.***> |
| Date | 12/02/2024 09:33 |
| To | vitejs/vite ***@***.***> |
| Cc | zhn ***@***.***>,
Author ***@***.***> |
| Subject | Re: [vitejs/vite] vite6 [commonjs--resolver] node_modules/testb/a.js (1:6): await isn't allowed in non-async function (Issue #18850) |
Yes, I have.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
My code is very simple. I think as long as Vite can skip the checks, vite-plugin-top-level-await can handle it. const remoteReact = await moduleFederation.import('react', "^18.0.1")
module.exports = remoteReact |
However, if there are other ways to implement this runtime module, I’m more than happy to make changes. |
It seems setting When Setting Instead of relying on the CJS plugin, you might be able to use the |
Can |
No, |
I previously used syntheticNamedExports, but I removed it to maintain consistency between the dev and build processes. |
I'm not sure why your code worked in dev. esbuild doesn't support top-level-await in CJS as well. |
I used to do it this way: But later, for consistency and simplicity, I changed it to: |
You’re right. Since chunks aren’t merged in dev mode, I can easily handle the replacement of top-level await. |
I see. I don't have any ideas other than (a) going back to |
ok thanks |
Describe the bug
Everything works fine with Vite 5.
Top-level await in node_modules.
module-federation/vite#201
Reproduction
https://github.com/zhangHongEn/vite-mf-bug
Steps to reproduce
npm install && npm run build
System Info
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: