Yarn workspaces expo amplify, Error: resolveDependencies: Found duplicate dependency key 'undefined' in
See original GitHub issueDo 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”
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:8 (1 by maintainers)
Top GitHub Comments
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
peerDependencies
and I did run npm install with--legacy-peer-deps
that 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 metro
was 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: