metro: Yarn workspaces expo amplify, Error: resolveDependencies: Found duplicate dependency key 'undefined' in
Do you want to request a feature or report a bug? bug
What is the current behaviour?
The app shows red box related to metro

If the current behaviour is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
I have setup Yarn workspaces mono repo with expo apps in /apps folder.
I also have amplify in the /packages folder.
By nature when I do amplify pull it gets an exact copy of what is up in AWS and hence I’ll end up package.json with same name throughout the code base. Yarn workspace is not happy with multiple package.json files with the same name field.
I am using the following code (blacklistRE) to ignore unwanted source code to be considered in metro
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");
const exclusionList = require("metro-config/src/defaults/exclusionList");
const workspaceRoot = path.resolve(__dirname, "../..");
const projectRoot = __dirname;
const config = getDefaultConfig(projectRoot);
config.watchFolders = [workspaceRoot];
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(workspaceRoot, "node_modules"),
];
module.exports = {
...config,
resolver: {
...config.resolver,
blacklistRE: exclusionList([/amplify\/#current-cloud-backend\/.*/]),
},
};
The code works just fine with "metro-config": "0.71.3" but when I upgrade to "metro-config": "0.72.0" I get the error as attached.
iOS Bundling failed 65ms
error: Error: resolveDependencies: Found duplicate dependency key 'undefined'
The command I am running is:
yarn workspace MyApp expo run:ios
Since there’s not much doc around mono repos and metro configs I thought I share my findings and in case that’s not a bug will be great if you guys can let me know what needs to be changed for the new version to work.
What is the expected behavior? No error
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system. OS: MacOs Montery npm: 8.13.2 yarn: 1.22.19 “metro-config”: “0.72.0”
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 16 (1 by maintainers)
In my case there was an issue with 2 versions of
metro. I have found it by runningnpm ls metro:So, removing the duplicated one resolved the issue.
The case is closed for me but only after deleting the library that contained a peerDependencies entry for metro-config v0.58 AND any mention of metro in my package.json (I had one, but removing that was not enough) Luckily I had a workaround for UI-kittens at https://akveo.github.io/react-native-ui-kitten/docs/design-system/customize-mapping#merge-mappings
I want to highlight that the metro dependency was in
peerDependenciesand I did run npm install with--legacy-peer-depsthat should not create duplicates. I am going to blame the cache even if I spent hours clearing it all over the place.Thanks again @robhogan the info you provided led me to the only possible conclusions: duplicates are not allowed and that’s it. I then spent time finding and killing them all (note that
npm ls metrowas a bit misleading when duplicates in peerDependencies were set to same version).On a final note I’d like to share a 1liner npm script I used a lot in fixing this issue. Hope it helps others:
We’ve only seen this with multiple Metro installations (specifically,
metro@>=0.72.0andmetro@<0.72.0).This is due to a new “dependency key”, added in https://github.com/facebook/metro/pull/835. This is required by newer Metro versions, but not supplied by older versions of the
collectDependenciesworker, which isrequired bymetro-transform-workerand can end up resolving to a different version of Metro.This might hint at the problem. Usually (ie, in a React Native context)
metrois indirect dependency via@react-native-community/cli, and shouldn’t normally be listed in your project’spackage.json.Even if you don’t have an explicit
metrodependency it is still sometimes possible to get multiple versions (see discussion) - if that happens, deleting your lockfile andnode_modulesand reinstalling should help.Running
npm ls metrooryarn why metroshould tell you conclusively if you have multiple versions installed in your project, and how. If you do only have one version installed, please reopen this issue and if possible include a version of youryarn.lockor a minimal repro.https://github.com/facebook/metro/issues/857#issuecomment-1264646138 Refer to above. Explained in better way.
Step 1: Uninstall @react-native-community/cli@7.0.4 Step 2: Install version from react-native package that is @react-native-community/cli@10.0.0 (Refer below image for versions)
For understand please check the image below
I’m having this exact same problem. Wondering if it could be caused by multiple
metroandmetro-configversions.I used to have 2 versions of metro, but removed the library that required it and still lo luck (after clearing any possible cache from watchman to metro and so on).
First: it wasn’t an issue until I had to update metro to 0.72 Second: I am puzzled by the undefined in “Found duplicate dependency key ‘undefined’ in”.
Anyone has any insight on this? Additionally I will need to add again the library depending on a different metro version, so what are my chances of fixing this? --legacy-peer-deps it’s itchy and still didn’t solve my problem (–force didn’t help either).
I have even tried to fork that library repo and changed it’s package.json but not cake.