Metro Bundler
raw JSON → 0.0.1 verified Sat Apr 25 auth: no javascript deprecated
Metro is the JavaScript bundler for React Native, designed for sub-second reload cycles, fast startup, and quick bundling speeds. It handles thousands of modules in a single application and is integrated with every React Native project out of the box. Version 0.0.1 appears to be a fork (prn-metro-bundler) of the original Facebook metro-bundler, but the npm package seems to be a placeholder or mis-published. The original metro-bundler was previously part of the react-native repository and is now maintained separately. Note: The correct npm package for the official Metro bundler is 'metro' (or 'metro-bundler' as an alias), but the version 0.0.1 shown here is likely a test/published fork from a Chinese company (pinguo-zhangzhi).
Common errors
error Cannot find module 'metro-bundler' ↓
cause The package 'metro-bundler' is deprecated and not available on npm (only historical).
fix
Install 'metro' instead: npm install metro
error require('metro-bundler') returns undefined ↓
cause Metro v0.50+ switched to ESM only; CommonJS require does not work.
fix
Use ES module import: import Metro from 'metro'
Warnings
gotcha This package (prn-metro-bundler v0.0.1) is a fork from pinguo-zhangzhi and is likely not the official Metro bundler. Use the official 'metro' package instead. ↓
fix Install 'metro' from npm: npm install metro
deprecated The official metro-bundler package is deprecated; use 'metro' instead. ↓
fix Replace 'metro-bundler' with 'metro' in package.json and imports.
breaking In Metro v0.50+, the API changed from default export to named exports. Old code using `const Metro = require('metro-bundler')` will break. ↓
fix Use named imports: `import { createServer } from 'metro'`.
Install
npm install prn-metro-bundler yarn add prn-metro-bundler pnpm add prn-metro-bundler Imports
- Metro wrong
const Metro = require('metro')correctimport Metro from 'metro' - runBuild wrong
import { runBuild } from 'metro-bundler'correctimport { runBuild } from 'metro' - createServer wrong
const createServer = require('metro-bundler').createServercorrectimport { createServer } from 'metro'
Quickstart
import Metro from 'metro';
import express from 'express';
const app = express();
const port = process.env.PORT || 8081;
// Start Metro bundler server
Metro.createServer().then(server => {
server.listen(port, () => {
console.log(`Metro bundler running on port ${port}`);
});
});
app.get('/', (req, res) => {
res.send('Hello from Metro bundler');
});
app.listen(3000, () => {
console.log('Express server listening on port 3000');
});