ctx.requireAsync()
Asynchronously loads UMD/AMD or globally mounted scripts via URL, as well as CSS. It is suitable for RunJS scenarios that require UMD/AMD libraries such as ECharts, Chart.js, FullCalendar (UMD version), or jQuery plugins. If a library also provides an ESM version, prioritize using ctx.importAsync().
Use Cases
Can be used in any RunJS scenario where UMD/AMD/global scripts or CSS need to be loaded on demand, such as JSBlock, JSField, JSItem, JSColumn, Workflow, JSAction, etc. Typical uses: ECharts, Chart.js, FullCalendar (UMD), dayjs (UMD), jQuery plugins, etc.
Type Definition
Parameters
Return Value
- The loaded library object (the first module value of the UMD/AMD callback). Many UMD libraries attach themselves to
window(e.g.,window.echarts), so the return value might beundefined. In such cases, access the global variable as per the library's documentation. - Returns the result of
loadCSSwhen a.cssfile is passed.
URL Format Description
- Shorthand path: e.g.,
echarts@5/dist/echarts.min.js. Under the default ESM CDN (esm.sh), it requestshttps://esm.sh/echarts@5/dist/echarts.min.js?raw. The?rawparameter is used to fetch the original UMD file instead of an ESM wrapper. - Full URL: Any CDN address can be used directly, such as
https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js. - CSS: A URL ending in
.csswill be loaded and injected into the page.
Difference from ctx.importAsync()
- ctx.requireAsync(): Loads UMD/AMD/global scripts. Suitable for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins, etc. Libraries often attach to
windowafter loading; the return value may be the library object orundefined. - ctx.importAsync(): Loads ESM modules and returns the module namespace. If a library provides ESM, use
ctx.importAsync()for better module semantics and Tree-shaking.
Examples
Basic Usage
ECharts Chart
Chart.js Bar Chart
dayjs (UMD)
Notes
- Return value format: UMD export methods vary; the return value may be the library object or
undefined. Ifundefined, access it viawindowaccording to the library's documentation. - Network dependency: Requires CDN access. In internal network environments, you can point to a self-hosted service via ESM_CDN_BASE_URL.
- Choosing between importAsync: If a library provides both ESM and UMD, prioritize
ctx.importAsync().
Related
- ctx.importAsync() - Loads ESM modules, suitable for Vue, dayjs (ESM), etc.
- ctx.render() - Renders charts and other components into a container.
- ctx.libs - Built-in React, antd, dayjs, etc., no asynchronous loading required.

