Installation
Your first React Native WebGPU App
React Native WebGPU brings the WebGPU API to iOS, Android, macOS, and visionOS using Dawn.
Install the package
npm i react-native-webgpuRequirements
| Package | Version | Required |
|---|---|---|
react-native | >= 0.81.0 | Yes |
react-native-worklets | >= 0.7.2 | Optional - off-js-thread rendering |
Please note that this module does not work on the legacy architecture.
iOS: Swift Package Manager
By default, react-native-webgpu links on iOS/macOS through CocoaPods autolinking - no extra setup needed. As an alternative, the package also ships a Package.swift for React Native's SwiftPM autolinking, which needs no CocoaPods at all:
- Use React Native 0.87 or newer. Earlier releases have no SwiftPM autolinking (
scripts/spm), so keep CocoaPods there. - From your app's
iosdirectory, runnpx react-native spm add --deintegrateonce. It removes CocoaPods from the project and injects the Swift packages into the.xcodeproj. Then build the project (not a workspace) as usual: React Native'sSync SPM Autolinkingbuild phase picksreact-native-webgpuup as a self-managed package and links itsReactNativeWebGPUproduct. - Do not run
pod installin that app: it would re-integrate CocoaPods and break the Swift package graph.
The manifest consumes React Native's headers as Swift package products (ReactHeaders, ReactNativeHeaders, ReactNativeDependenciesHeaders, plus the app's generated ReactAppHeaders for the RNWgpuViewSpec codegen output), so no CocoaPods install is involved. If a Graphite build of @shopify/react-native-skia is installed alongside, the manifest also checks that both packages link the same Dawn release and fails package resolution on a mismatch (see React Native Skia). SwiftPM caches manifest evaluations, so after changing either package's Dawn version reset the package caches in Xcode (File > Packages > Reset Package Caches) if the check does not re-run. The manifest follows the same integration model as @shopify/react-native-skia's own Package.swift, so the two libraries link the same way.
Package.swift's WebGPUDawn binary target resolves to a prebuilt Dawn .xcframework published on GitHub Releases; Xcode downloads and checksum-verifies it the first time it resolves packages.
Platform coverage
The Swift package targets iOS only - macOS, Android and visionOS still require the CocoaPods/Gradle autolinked path. See spm-example at the root of the react-native-webgpu repo for a working reference project, and its README for the gotchas (stale Package.resolved, the stub Podfile).
Setup
Once installed, the global navigator.gpu API is available - the same entry point as in Chrome or Safari:
const = await ..();
const = await !.();Rendering happens inside a Canvas view. The typical loop is:
- Get a WebGPU context from the canvas ref
- Configure the context with your device
- Encode render (or compute) passes
device.queue.submit(...)context.present()- required on React Native (Frame presentations)
Start with the Canvas view once installation is done.
Testing with Jest
react-native-webgpu wraps a native module, which isn't available under Jest. Add its mock to setupFilesAfterEnv in your jest.config.js:
// jest.config.js
module.exports = {
// Other values
setupFilesAfterEnv: [
"react-native-webgpu/jestSetup.js",
],
};This replaces the package with a JS-only stand-in: <Canvas> renders as a plain View so screens built around it can still be rendered in tests, while GPU-dependent APIs (importDevice, adoptTexture, useDevice, a real canvas context) throw a clear error if a test actually exercises them.
Troubleshooting
Android emulators
On Android emulators, WebGPU may fall back to a software adapter. Rendering is slow and some features (especially native textures) may be unavailable. Use warnIfNotHardwareAccelerated to log a warning during development. Prefer physical devices for camera, video, and performance testing.
iOS Simulator - Metal API Validation
When running on the iOS Simulator, disable Metal API Validation in Xcode or you may hit false-positive errors and crashes that do not occur on device.
Expo: add the config plugin that ships with react-native-webgpu to your app config - it disables the setting automatically on every prebuild:
{
"expo": {
"plugins": ["react-native-webgpu"]
}
}Bare React Native: Product → Scheme → Edit Scheme → Run → Diagnostics → uncheck Metal API Validation.
Metal API Validation is a debug mode that checks every Metal call against the API specification. The simulator's Metal stack is not identical to real hardware, and validation can flag legitimate Dawn/WebGPU usage as invalid. Disabling it for local development is standard practice; keep validation enabled when debugging raw Metal code on device if needed.
Learn more in Apple's documentation on validating Metal API usage.
Next steps
- Expo - scaffold the hosted WebGPU examples template
- Canvas - your rendering surface
- Native APIs - the React Native specific differences
- Learn WebGPU - learn the low-level API