react_native_dependencies

Locked JavaScript dependencies for React Native.

Description#

Reads package.json, one supported lockfile, and an optional normalized module snapshot during graph loading. The resolver records exact React Native and Hermes versions, emits one react_native_module target per snapshotted native package, and runs a frozen package-manager install as a cacheable action.

Package managerLockfileFrozen install
npmpackage-lock.jsonnpm ci
pnpmpnpm-lock.yamlpnpm install --frozen-lockfile
Yarnyarn.lock--frozen-lockfile for Yarn 1, --immutable for modern Yarn
Bunbun.lockbun install --frozen-lockfile

Set package_manager explicitly or leave it as auto. Automatic selection uses an explicit lockfile path first, then package.json's packageManager field, then the only supported lockfile supplied to the resolver.

Modern Yarn installs with its node-modules linker. pnpm public-hoists only @react-native/*, which makes the React Native Gradle plugin available at the conventional path expected by checked-in Android projects. Bun uses its hoisted linker.

The installed dependency tree is the shared input for Metro, Codegen, autolinking, and native application targets.

Include repository-local file: packages in srcs. Struo stages those files beside the package manifest before installation, so the selected manager creates valid local links and changes to those packages invalidate the dependency action.

Use package_manager_files for text configuration such as .npmrc or .yarnrc.yml. Each file must also be present in resolver_inputs. Configuration must not contain authentication tokens or passwords because declared inputs may be uploaded to a shared cache. Include binary manager files such as an offline package archive in srcs, not resolver_inputs.

Attributes#

AttributeTypeRequiredDefaultDescription
package_jsonstringnopackage.jsonJavaScript package manifest; in a monorepo, the root one that declares workspaces
package_managerstringnoautoauto, npm, pnpm, yarn, or bun
package_manager_executablestringnoPackage manager executable override
lockfilestringnoLockfile path, detected when omitted
npmrcstringnoOptional npm configuration without credentials
package_manager_fileslist<string>no[]Additional text configuration without credentials
modules_snapshotstringnoNormalized native-module snapshot
resolver_inputslist<string>no[]Text inputs available to the resolver
nodestringnonodeNode.js executable
allow_networkboolnofalsePermit package downloads missing from the local cache
install_argslist<string>no[]Additional frozen-install arguments

Underscore-prefixed attributes are resolver-owned and must not be set by a package manifest.

Providers and capabilities#

The target emits javascript_dependency_set and react_native_dependency_set. Its build capability exposes node_modules.

Package lifecycle scripts run during installation. allow_network = false uses each manager's offline mode and cache, but it does not sandbox direct network or filesystem access by lifecycle scripts. Bun currently offers a prefer-offline mode rather than a strict offline install, so a cache miss may still reach the registry.

The dependency action caches the complete staged installation workspace, including lifecycle-generated files outside node_modules. Include script programs and their repository-local inputs in srcs so changes invalidate the installation. Cache replay restores generated files as well as dependencies. This does not automatically copy those generated files into consumer source workspaces; consumers still need an explicit source boundary.

In a monorepo, declare the target at the workspace root and list every workspace member's package.json in srcs. See Monorepos.

Switching package managers can also change native podspec checksums, so regenerate and check in Podfile.lock after a switch.

Example#

toml
[[target]] name = "Dependencies" kind = "react_native_dependencies" srcs = [ "package.json", "pnpm-lock.yaml", "react-native-modules.json", "packages/native-camera/**/*", ] [target.attrs] package_manager = "pnpm" lockfile = "pnpm-lock.yaml" modules_snapshot = "react-native-modules.json" resolver_inputs = ["package.json", "pnpm-lock.yaml", "react-native-modules.json"]