Static Resources With async Functions

When you use lightning/platformResourceLoader in Lightning web components to access static resources and Lightning Web Security (LWS) is enabled, it’s possible that some APIs in those static resources exhibit inconsistent behavior among various browsers.

When LWS is enabled, JavaScript async functions that are used from a static resource work in Chromium-based browsers, but don't work in Firefox currently. The issue is a bug in Firefox.

You can get around this issue in Firefox by pre-compiling the code that’s in the static resource so the async function is replaced by equivalent code.

This Babel plugin is recommended if you’re having issues with async functions in static resources: https://babeljs.io/docs/en/babel-plugin-transform-async-to-generator

Alternatively, you can refactor to use another approach, such as JavaScript promises.

See Also