> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# lynx: requireModuleAsync() static method

APISummary
Used to import modules. Just like the [`requireModule`](/next/api/lynx-api/lynx/lynx-require-module.md) method, but loading asynchronously.

During the loading, the other JavaScript code can be executed.

The module loaded by `requireModuleAsync` needs to use a specific format. Use [`@lynx-js/runtime-wrapper-webpack-plugin`](https://www.npmjs.com/package/@lynx-js/runtime-wrapper-webpack-plugin) to generate modules that are `requireModuleAsync`-loadable.

## Syntax

```ts
requireModuleAsync<T>(path: string, callback: (error: Error | null, exports?: T) => void): void;
```

### Parameters

#### path

The path of the module. Can be a remote path, or a path inside the template.

#### callback

The callback to be executed after the require is finished

- If any error occurs, an error will be passed as the first parameter.
- Otherwise, a `null` will be passed as the first parameter, and the exported value of the module will be passed as the second parameter.

### Return Value

None (`undefined`).

## Exception

`requireModuleAsync` will return an error in callback when:

- Network error
- Module execute error

## Examples

### Loading remote resources

```tsx
lynx.requireModuleAsync('https://example.com/path/to/chunk', (err, exports) => {
  if (err) {
    return;
  }
  // use exports
});
```

### Promisify

```js
const requireModulePromise = (path) =>
  new Promise((resolve, reject) => {
    lynx.requireModuleAsync(path, (err, exports) => {
      if (err) {
        return reject(err);
      }
      return resolve(exports);
    });
  });

await requireModulePromise('path/to/chunk');
```

## Compatibility

**Compatibility Table**

**Query:** `lynx-api.lynx.requireModuleAsync`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/lynx/requireModuleAsync.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| requireModuleAsync | Yes (1.4) | Yes (3.4) | Yes (1.4) | Yes (3.5) | Yes (3.5) | Yes |

**`requireModuleAsync`**

Used to import modules.

