Loading...
Loading...
Builds React Native Nitro Modules from scratch in a monorepo. Scaffolds with Nitrogen, authors HybridObject TypeScript specs, generates native boilerplate, implements in C++/Swift/Kotlin, wires an example app, and prepares for npm publishing. Use when creating a new Nitro Module, implementing native functionality via HybridObjects, or setting up the nitrogen codegen pipeline.
npx skill4agent add margelo/react-native-skills build-nitro-modulesnitrogen.nitro.tsNEVER modify any file inside. These files are fully regenerated every timenitrogen/generated/runs — any manual edits will be silently overwritten. Always edit only thenpx nitrogenspec file, then re-run nitrogen to regenerate..nitro.ts
"Are you creating a new Nitro Module library from scratch, or adding a new HybridObject to an existing library?"
react-native-mathpackages/packages/<name>swiftcppkotlincppcppCameraCryptoswiftcppkotlincpp# 1. Scaffold
npx nitrogen@latest init react-native-math
# 2. Run codegen (from package folder after writing spec + nitro.json)
cd packages/react-native-math && npx nitrogen
# 3. Create example app
npx @react-native-community/cli@latest init --skip-install MathExample
# 4. Install and test
cd example && bun add ../packages/react-native-math
bun add react-native-nitro-modules
bun example android
bun example ios*.nitro.ts| Priority | Category | Impact | Reference |
|---|---|---|---|
| 1 | Monorepo scaffold | CRITICAL | setup-monorepo-init.md |
| 2 | HybridObject spec | CRITICAL | spec-hybrid-object.md |
| 3 | nitro.json autolinking | CRITICAL | spec-nitro-json.md |
| 4 | Nitrogen codegen | HIGH | native-nitrogen-codegen.md |
| 5 | C++ implementation | HIGH | native-implement-cpp.md |
| 6 | Kotlin implementation | HIGH | native-implement-kotlin.md |
| 7 | Swift implementation | HIGH | native-implement-swift.md |
| 8 | Example app setup (if requested) | HIGH | example-app-setup.md |
| 9 | Android Gradle paths (if example app) | HIGH | example-android-config.md |
| 10 | Metro + install + test (if example app) | HIGH | example-metro-install.md |
| 11 | npm publish prep | MEDIUM | spec-package-publish.md |
src/specs/Math.nitro.tsimport { type HybridObject, NitroModules } from 'react-native-nitro-modules'
interface Math extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
add(a: number, b: number): number
}
const math = NitroModules.createHybridObject<Math>('Math')
export { math }nitro.json{
"$schema": "https://nitro.margelo.com/nitro.schema.json",
"cxxNamespace": ["math"],
"ios": { "iosModuleName": "ReactNativeMath" },
"android": {
"androidNamespace": ["math"],
"androidCxxLibName": "ReactNativeMath"
},
"autolinking": {
"Math": { "swift": "HybridMath", "kotlin": "HybridMath" }
}
}package.json{
"scripts": {
"specs": "bun --cwd packages/react-native-math run specs",
"example": "bun --cwd example"
}
}bun example androidbun example iosbun specs| File | Description |
|---|---|
| setup-monorepo-init.md | Monorepo workspace structure and |
| spec-hybrid-object.md | Writing |
| spec-nitro-json.md | |
| native-nitrogen-codegen.md | Running Nitrogen and verifying generated files |
| native-implement-cpp.md | Implementing HybridObjects in C++ |
| native-implement-kotlin.md | Implementing HybridObjects in Kotlin (Android) |
| native-implement-swift.md | Implementing HybridObjects in Swift (iOS) |
| example-app-setup.md | RN CLI example app init, workspace wiring, version alignment |
| example-android-config.md | |
| example-metro-install.md | Metro watchFolders, library install, App.tsx usage, test runs |
| spec-package-publish.md | |
| Problem | Reference | Action |
|---|---|---|
| Don't know where to start | setup-monorepo-init.md | Scaffold with |
| Spec file syntax error | spec-hybrid-object.md | Fix |
| Autolinking not working | spec-nitro-json.md | Check |
| Nitrogen generates no files | native-nitrogen-codegen.md | Verify spec file extension and run command from right dir |
| C++ types unclear | native-implement-cpp.md | Follow type reference links to canonical examples |
| Kotlin compilation error | native-implement-kotlin.md | Check annotations and |
| Swift compilation error | native-implement-swift.md | Check class inheritance and property signatures |
| Example app won't build (Android) | example-android-config.md | Fix Gradle monorepo path configuration |
| Metro can't resolve library | example-metro-install.md | Add |
| Version mismatch between example and package | example-app-setup.md | Align |
| Package missing files on npm | spec-package-publish.md | Fix |