In RunJS you can use two kinds of modules: built-in modules (via ctx.libs, no import needed) and external modules (loaded on demand via ctx.importAsync() or ctx.requireAsync()).
RunJS provides common libraries via ctx.libs; you can use them directly without import or async loading.
| Property | Description |
|---|---|
| ctx.libs.React | React core for JSX and Hooks |
| ctx.libs.ReactDOM | ReactDOM (e.g. for createRoot) |
| ctx.libs.antd | Ant Design components |
| ctx.libs.antdIcons | Ant Design icons |
| ctx.libs.math | Math.js: math expressions, matrix operations, etc. |
| ctx.libs.formula | Formula.js: Excel-like formulas (SUM, AVERAGE, etc.) |
For third-party libraries, choose the loader by module format:
ctx.importAsync()ctx.requireAsync()Use ctx.importAsync() to load ESM modules by URL at runtime. Suitable for JS Block, JS Field, JS Action, etc.
<package>@<version> or subpath <package>@<version>/<path> (e.g. vue@3.4.0, lodash@4/lodash.js), which is resolved with the configured CDN prefix; full URLs are also supported.When not configured, the shorthand form uses https://esm.sh as the CDN prefix. For example:
For intranet or custom CDN, deploy an esm.sh-compatible service and set:
https://esm.sh)/+esm)Reference: https://github.com/nocobase/esm-server
Use ctx.requireAsync() to load UMD/AMD scripts or scripts that attach to the global object by URL.
<package>@<version>/<path>, same as ctx.importAsync(); resolved with the current ESM CDN config; ?raw is appended to request the raw file (usually UMD). E.g. echarts@5/dist/echarts.min.js becomes https://esm.sh/echarts@5/dist/echarts.min.js?raw when using default esm.sh.https://cdn.jsdelivr.net/npm/xxx).Many UMD libraries attach to the global (e.g. window.xxx); use them as documented.
Example
Note: If a library provides both ESM and UMD, prefer ctx.importAsync() for better module semantics and tree-shaking.