{"library":"metro-bundler-config-yarn-workspaces","title":"Metro Bundler Config for Yarn Workspaces","description":"This package provides a utility to generate an appropriate Metro bundler configuration for React Native projects operating within a Yarn Workspaces monorepo. It simplifies the complex setup required to ensure Metro correctly resolves modules, handles hoisted dependencies, and watches all necessary folders across the workspace, addressing common pitfalls associated with monorepo structures like symlinks and duplicate package resolution. The current stable version is 1.0.3. As a configuration helper, its release cadence is typically infrequent, tied to significant updates in Metro, React Native, or Yarn Workspaces that necessitate changes in bundling logic. Its key differentiator is automating the often manual and error-prone process of configuring `metro.config.js` to correctly interpret the monorepo's dependency graph, providing a streamlined approach compared to manually managing `watchFolders`, `nodeModulesPaths`, and resolver configurations.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install metro-bundler-config-yarn-workspaces"],"cli":null},"imports":["const getMetroConfig = require('metro-bundler-config-yarn-workspaces');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const path = require('path');\nconst getMetroConfig = require('metro-bundler-config-yarn-workspaces');\n\n// Determine the root of your monorepo. If metro.config.js is in 'apps/my-app/',\n// then the workspace root is '../..' relative to this file.\nconst projectRoot = __dirname;\nconst workspaceRoot = path.resolve(projectRoot, '../..');\n\nmodule.exports = getMetroConfig({\n  projectRoot,\n  workspaceRoot,\n  // Add any additional watch folders specific to your monorepo setup,\n  // for example, if you have a 'shared' packages directory.\n  watchFolders: [\n    path.resolve(workspaceRoot, 'packages'), // Example: if shared packages are in a 'packages' dir\n    path.resolve(workspaceRoot, 'node_modules') // Ensure hoisted node_modules are watched\n  ],\n  // Optionally, customize resolver options if needed, e.g., for specific assets or extensions.\n  // resolver: {\n  //   extraNodeModules: {\n  //     'react-native': path.resolve(projectRoot, 'node_modules/react-native')\n  //   },\n  //   assetExts: ['db', 'json', 'wasm', 'txt', 'jpg', 'png', 'ttf'],\n  //   sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs']\n  // }\n});","lang":"javascript","description":"Demonstrates how to integrate this package into a `metro.config.js` file for a React Native project within a Yarn Workspaces monorepo, configuring paths for module resolution and file watching.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}