Skip to main content

metro-plugin-duplicates-checker

@rnx-kit/metro-plugin-duplicates-checker checks for duplicate packages in your bundle.

Usage

There are several ways to use this package.

The recommended way is to add it as a plugin in your metro.config.js using @rnx-kit/metro-serializer:

const { makeMetroConfig } = require("@rnx-kit/metro-config");
const {
DuplicateDependencies,
} = require("@rnx-kit/metro-plugin-duplicates-checker");
const { MetroSerializer } = require("@rnx-kit/metro-serializer");

module.exports = makeMetroConfig({
projectRoot: __dirname,
serializer: {
customSerializer: MetroSerializer([DuplicateDependencies()]),
},
});

You can also check for duplicate packages after a bundle is created:

const {
checkForDuplicatePackagesInFile,
} = require("@rnx-kit/metro-plugin-duplicates-checker");

checkForDuplicatePackagesInFile(pathToSourceMapFile, {
ignoredModules: [],
bannedModules: [],
});

If you have a source map object, you can pass that directly to checkForDuplicatePackages():

const {
checkForDuplicatePackages,
} = require("@rnx-kit/metro-plugin-duplicates-checker");

checkForDuplicatePackages(mySourceMap, {
ignoredModules: [],
bannedModules: [],
});

Options

KeyTypeDefaultDescription
bannedModulesstring[][]List of modules that are banned.
ignoredModulesstring[][]List of modules that can be ignored.
throwOnErrorbooleantrueWhether to throw when duplicates are found.