-
Notifications
You must be signed in to change notification settings - Fork 12k
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
ERROR: Top-level await is not available in the configured target environment #26507
Comments
Hi, do you use a custom browserlist ? |
Almost all default configurations |
can you give us the |
Of course, as follows: |
Exception information seen in the browser console: core.mjs:10614 ERROR Error: Uncaught (in promise): TypeError: Failed to fetch dynamically imported module: http://localhost:4200/.angular/cache/16.2.10/vite/deps/pdfjs-dist.js?v=a9ded181
TypeError: Failed to fetch dynamically imported module: http://localhost:4200/.angular/cache/16.2.10/vite/deps/pdfjs-dist.js?v=a9ded181
at resolvePromise (zone.js:1193:31)
at resolvePromise (zone.js:1147:17)
at zone.js:1260:17
at _ZoneDelegate.invokeTask (zone.js:402:31)
at core.mjs:10757:55
at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:10757:36)
at _ZoneDelegate.invokeTask (zone.js:401:60)
at Object.onInvokeTask (core.mjs:11070:33)
at _ZoneDelegate.invokeTask (zone.js:401:60)
at _Zone.runTask (zone.js:173:47) |
From the logs, it appears that the project is using the new build system with Angular v16. For v16, the build system was considered a developer preview and may not operate as expected in all cases. Please consider updating to Angular v17 where the new build system is now stable and fully supported. If you are still encountering issues after using v17, please provide an updated version output as well as a minimal reproduction demonstrating the problem so that we can investigate further. |
@clydin Thank you for your reply, here is a demo: |
This is expected as top level awaits are not supported. Angular uses Zone.js which in requires always async/await to be downlevelled, in Esbuild this is done by enabling This is because we enable async/await downlevelling in esbuild which disables top level await usage. Let's keep tracking this in #22191 |
@alan-agius4 Thank you for your reply, as far as I know this vite plugin |
In this case adding the plugin in vite will only fix it it when running |
You can see how to config the plugin here https://www.npmjs.com/package/vite-plugin-top-level-await |
For those who experience the same issue in the both dev and build commands, add the following // vite.config.js
optimizeDeps: {
esbuildOptions: {
target: 'esnext'
}
},
build: {
target: 'esnext'
} |
@madurapa can you please share the complete config file. I'm not sure where to add optimizeDeps and build. |
The vite config is internal to the CLI and cannot be modified. As stated before top level await is not supported. |
@alan-agius4 topLevelAwait is enabled by default in Webpack but disabled in angular. Is there a chance you could enable it so we won't need custom webpack builder? |
@benbro, no, as that would cause the application not to be buildable if you decide to migrate to the esbuild based builders. See #26507 (comment) |
export default defineConfig({
optimizeDeps: {
esbuildOptions: {
target: 'esnext'
}
},
build: {
target: 'esnext'
},
}); Put your config if you find it difficult to edit, I can include those values and past here |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: