> 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: requireModule() static method

APISummary
Used to import modules. Just like NodeJS's [`require`](https://nodejs.org/docs/latest/api/modules.html#requireid).

`requireModule` will load the module **synchronously**. During the loading, the JavaScript thread will be hang. No JavaScript code will be executed.

## Syntax

```ts
requireModule<T>(path: string): T;
```

### Parameters

#### path

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

### Return Value

The exported value of the module.

## Exception

`requireModule` will throw an exception when:

- Network error
- Module execute error
- Timeout

The error can be catch and handled by using `try-catch`.

### Timeout

To avoid JavaScript thread hang forever when loading remote resources, `requireModule` will throw an exception 5 seconds after the request is sent.

## Examples

### Loading remote resources

```tsx
const foo = lynx.requireModule('https://example.com/path/to/chunk');
```

### Re-try on timeout

```js
let result = null;
(function () {
  let retry = 0;
  function requireModule(path) {
    try {
      result = lynx.requireModule(path);
    } catch (error) {
      retry += 1;
      if (retry < 3) {
        requireModule(path);
      } else {
        throw error;
      }
    }
  }
  requireModule('path/to/chunk');
})();
```

## Compatibility

**Compatibility Table**

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

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

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

**`requireModule`**

Used to import modules and JSON.

