Skip to main content

metro-plugin-cyclic-dependencies-detector

Build npm version

@rnx-kit/metro-plugin-cyclic-dependencies-detector detects cyclic import chains that may cause issues in your bundle.

Usage

Import and add the plugin to MetroSerializer in your metro.config.js, and optionally configure it to your liking:

 const { makeMetroConfig } = require("@rnx-kit/metro-config");
+const {
+ CyclicDependencies,
+} = require("@rnx-kit/metro-plugin-cyclic-dependencies-detector");
+const { MetroSerializer } = require("@rnx-kit/metro-serializer");

module.exports = makeMetroConfig({
serializer: {
+ customSerializer: MetroSerializer([
+ CyclicDependencies({
+ includeNodeModules: false,
+ linesOfContext: 1,
+ throwOnError: true,
+ }),
+ ]),
},
});

Options

KeyTypeDefaultDescription
includeNodeModulesbooleanfalseWhether to scan node_modules.
linesOfContextnumber1Number of extra modules to print for context.
throwOnErrorbooleantrueWhether to throw when cycles are detected.