---
sidebar_position: 2
title: Installation
pagination_next: tutorials/concurrency-model
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Installation
Check the [compatibility table](../guides/compatibility.mdx) to find the Worklets version that supports your React Native version.
Worklets 1.0 needs Metro 0.88.0 or newer and React Native 0.89 or newer, which together support [inline modules](../bundleMode/setup.mdx#use-a-metro-with-inline-modules).
## Step 1: Install the package
Install `react-native-worklets` package from npm:
```bash
npm install react-native-worklets
```
```bash
yarn add react-native-worklets
```
## Step 2: Configure your project
The remaining steps depend on how you build your app — pick your framework:
Run prebuild to update the native code in the `ios` and `android` directories.
```bash
npx expo prebuild
```
```bash
yarn expo prebuild
```
And that's it! The Worklets library is now configured in your Expo project.
Don't I need the Worklet Syntax Babel plugin?
Since [Expo SDK 54](https://expo.dev/changelog/sdk-54-beta#notable-breaking-changes), the Expo starter template includes the Worklet Syntax Babel plugin by default, so there's nothing to add. On older SDKs, add `react-native-worklets/plugin` to your `babel.config.js` as described in the React Native Community CLI tab.
To learn more about the plugin go to [Worklet Syntax plugin](../worklets-plugin/about.mdx) section.
### Configure Metro
Worklets run in [Bundle Mode](../bundleMode/overview.mdx), which needs a Metro configuration. Follow the [Metro steps of the Bundle Mode setup](../bundleMode/setup.mdx#configure-metro) before you start the app.
### Clear Metro bundler cache (recommended)
```bash
npx expo start --clear
```
```bash
yarn expo start --clear
```
When using [React Native Community CLI](https://github.com/react-native-community/cli), you need to manually add the `react-native-worklets/plugin` plugin to your `babel.config.js`.
```js {7}
module.exports = {
presets: [
... // don't add it here :)
],
plugins: [
...
'react-native-worklets/plugin',
],
};
```
The Worklet Syntax Babel plugin comes with several options, you can explore what they are and how to use them in the [Options for Worklet Syntax Babel plugin](../worklets-plugin/options.mdx) section.
Why do I need this?
In short, the Worklet Syntax plugin automatically converts special JavaScript functions (called [worklet functions](../tutorials/0-concurrency-model.mdx#worklet-functions)) to allow them to be passed and run on the [Worklet Runtimes](../concepts/runtimeKinds.mdx#worklet-runtime)
To learn more about the plugin go to [Worklet Syntax plugin](../worklets-plugin/about.mdx) section.
### Configure Metro
Worklets run in [Bundle Mode](../bundleMode/overview.mdx), which needs a Metro configuration. Follow the [Metro steps of the Bundle Mode setup](../bundleMode/setup.mdx#configure-metro) before you start the app.
### iOS
While developing for iOS, make sure to install [pods](https://cocoapods.org/) first before running the app:
```bash
cd ios && pod install && cd ..
```
### Clear Metro bundler cache (recommended)
```bash
npm start -- --reset-cache
```
```bash
yarn start --reset-cache
```
## Step 3: Patch `metro-runtime` for Fast Refresh
:::caution Temporary
Fast Refresh on Worklet Runtimes uses `HMRClient.addModuleUpdateListener` from `metro-runtime`. This API is proposed in [react/metro#2312](https://github.com/react/metro/pull/2312) and no Metro release has it yet. Until one does, apply the patch below to `metro-runtime` 0.88, for example with `yarn patch metro-runtime` or `patch-package`. It adds the API to `src/modules/HMRClient.js`. Without the patch, a worklet function that Fast Refresh changes fails on Worklet Runtimes until you reload the app.
```diff
diff --git a/src/modules/HMRClient.js b/src/modules/HMRClient.js
--- a/src/modules/HMRClient.js
+++ b/src/modules/HMRClient.js
@@ -2,7 +2,18 @@
const EventEmitter = require("./vendor/eventemitter3");
const HEARTBEAT_INTERVAL_MS = 20_000;
+const moduleUpdateListeners = new Set();
const inject = ({ module: [id, code], sourceURL }) => {
+ Array.from(moduleUpdateListeners).forEach(({ listener }) => {
+ try {
+ listener(code, sourceURL);
+ } catch (error) {
+ console.error(
+ `Error while calling a module update listener for module ${id}: `,
+ error,
+ );
+ }
+ });
if (global.globalEvalWithSourceUrl) {
global.globalEvalWithSourceUrl(code, sourceURL);
} else {
@@ -14,6 +25,15 @@
update.modified.forEach(inject);
};
class HMRClient extends EventEmitter {
+ static addModuleUpdateListener(listener) {
+ const entry = { listener };
+ moduleUpdateListeners.add(entry);
+ return {
+ remove: () => {
+ moduleUpdateListeners.delete(entry);
+ },
+ };
+ }
_isEnabled = false;
_pendingUpdate = null;
_queue = [];
```
:::