Rocket Bundler

raw JSON →
0.14.2 verified Sat Apr 25 auth: no javascript

Rocket Bundler is the JavaScript bundler for React Native, optimized for fast reload cycles, startup, and bundling speeds. It is designed to scale with thousands of modules and is integrated by default in React Native projects. The current stable version is 0.14.2. Unlike generic bundlers (Webpack, Parcel), it is purpose-built for React Native's Metro-compatible API and ecosystem. It was formerly part of the react-native repository to allow more focused maintenance and faster issue response.

error Error: Cannot find module 'rocket-bundler'
cause Package not installed or used in a Node.js version that doesn't support ESM.
fix
npm install rocket-bundler@latest. Ensure Node.js >=14.8.0 and that the project's package.json has 'type': 'module' or use .mjs files.
error TypeError: (0 , rocket_bundler.bundle) is not a function
cause Attempting to import named exports as default or using CommonJS require.
fix
Use import { bundle } from 'rocket-bundler'. Do not use const rocket = require('rocket-bundler') as it returns undefined.
error Error: Bundle output path not specified
cause Missing bundleOutput option in the bundle() call.
fix
Add bundleOutput: './path/to/output.js' to the options object.
error Error: getPlatformExtension is not a function
cause Custom resolveRequest function not returning a proper extension.
fix
Implement resolveRequest according to the documentation: it must call getPlatformExtension on the request.
breaking rocket-bundler v0.14.0 removed the CommonJS entry point. Require('rocket-bundler') will throw 'ERR_REQUIRE_ESM'.
fix Switch to import syntax and ensure your Node.js version supports ESM (>=14.8.0).
deprecated The CLI interface (src/cli.js) is deprecated since v0.13.0 and will be removed in v1.0. Use the programmatic API instead.
fix Migrate to using the { bundle } and { Server } imports directly.
gotcha The base-file and base-output options (for incremental builds) are not stable across cache clears. Don't rely on them for production caching.
fix Set cacheVersion or manually clear caches instead.
gotcha Rocket Bundler uses a custom resolution algorithm similar to Metro. Node module resolution (require.resolve) may fail in some edge cases with symlinks.
fix Use 'require.resolve' with absolute paths or configure resolver.nodeModulesPaths.
breaking Platform-specific extensions (e.g., .ios.js, .android.js) are resolved with lower priority than in Metro. This is intentional but may break some existing projects.
fix Explicitly set resolver.resolveRequest to a function that reorders platform-specific extensions.
npm install rocket-bundler
yarn add rocket-bundler
pnpm add rocket-bundler

Shows how to load configuration and bundle a React Native app using the rocket-bundler API.

import { bundle } from 'rocket-bundler';
import { loadConfig } from 'rocket-bundler';

const config = await loadConfig({
  projectRoot: './',
  transformer: {
    babelTransformerPath: require.resolve('metro-react-native-babel-transformer'),
  },
  serializer: {
    // custom serializer options
  },
});

const result = await bundle({
  config,
  entryFile: 'index.js',
  platform: 'android',
  dev: false,
  bundleOutput: './output.js',
  sourceMapOutput: './output.map',
});

console.log('Bundle size:', result.stats.files['bundle'].size);