metro-symlinked-deps is a utility package designed to configure the Metro bundler, primarily used in React Native development, to overcome its inherent lack of support for symlinks. This deficiency often hinders local development workflows involving `yarn link` or `npm link` for shared dependencies by preventing Metro from resolving modules correctly across symlinked directories. Version 2.0.0 is the current stable release, which maintains compatibility with various `metro-config` versions by designating it as a peer dependency, thereby avoiding duplicate installations. The package provides a streamlined, automatic configuration function, `applyConfigForLinkedDependencies`, which intelligently manages Metro's `resolver.blacklistRE` and `watchFolders` settings. It addresses a long-standing issue in Metro (and its reliance on `jest-haste-map`) by allowing developers to integrate symlinked packages into their build process seamlessly. While not on a strict release cadence, it is updated as needed to address dependency changes and maintain its workaround effectiveness as long as Metro's native symlink issue persists.
npm install metro-symlinked-depsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `metro-symlinked-deps` into your `metro.config.js` to enable symlink support. It automatically applies the necessary configurations, explicitly sets the project root for robustness, and includes common options like blacklisting modules and adding watch folders.
Ensure `metro-symlinked-deps` is correctly applied in your `metro.config.js`. Always clear the Metro cache (`npx react-native start --reset-cache`) after making configuration changes or linking new dependencies.
Always specify the `projectRoot` option for robustness, typically using `__dirname` within your `metro.config.js`: `{ projectRoot: __dirname }`.Use the `blacklistLinkedModules` option to explicitly ignore problematic modules, e.g., `{ blacklistLinkedModules: ['react-native'] }`. Remember to reset the Metro cache (`npx react-native start --reset-cache`) after applying these changes.Add `metro-config` to your project's `devDependencies` (or `dependencies`) and ensure it's installed. For example: `yarn add metro-config` or `npm install metro-config`.
Verify that `metro-symlinked-deps` is correctly applied in your `metro.config.js`. Ensure `projectRoot` and `additionalWatchFolders` are accurately configured to include your linked packages. Always run `npx react-native start --reset-cache` after making changes to your configuration or linking new dependencies.
Add `react-native` to the `blacklistLinkedModules` option in your `metro-symlinked-deps` configuration within `metro.config.js`: `{ blacklistLinkedModules: ['react-native'] }`. Subsequently, clear the Metro cache using `npx react-native start --reset-cache`.Ensure your `metro.config.js` exclusively uses CommonJS `require()` and `module.exports` syntax, as demonstrated in the package's examples. If you intend to use ESM, your project's Node.js environment and Metro's configuration would need specific, advanced setup (e.g., setting `"type": "module"` in `package.json` and ensuring compatibility).