Doing a React Native update from 0.69.5 to 0.70.3.
App is building on both platforms, but when it runs on Metro this error comes up.
error: Error: resolveDependencies: Found duplicate dependency key 'undefined' in /Users/LA/Repo/sb-app/index.js at resolveDependencies (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/graphOperations.js:484:13)
error: Error: resolveDependencies: Found duplicate dependency key 'undefined' in /Users/LA/Repo/sb-app/index.js
at resolveDependencies (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/graphOperations.js:484:13)
at processModule (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/graphOperations.js:232:31)
at async traverseDependenciesForSingleFile (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/graphOperations.js:221:3)
at async Promise.all (index 0)
at async initialTraverseDependencies (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/graphOperations.js:204:3)
at async DeltaCalculator._getChangedDependencies (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:208:25)
at async DeltaCalculator.getDelta (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:90:16)
at async DeltaBundler.buildGraph (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler.js:56:5)
at async IncrementalBundler.buildGraphForEntries (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/IncrementalBundler.js:81:19)
at async IncrementalBundler.buildGraph (/Users/LA/Repo/sb-app/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/IncrementalBundler.js:161:19)
Following the error file locations only takes me to the ‘throw’ statements, and, of course there are no duplicate deps on index.js or app.tsx, as i’m assuming the error is just being thrown upwards to that file. I think…
Anyway, this has stumped me and my team for two days straight now, hoping someone else might have run into this and knows how to debug it. The undefined
key is 0% helpful.
I haven’t seen this error posted on stack or github so posting it here.
3
Answers
It is known problem, try to follow instructions from metro GitHub repository for this issue https://github.com/facebook/metro/issues/857
I have experienced this problem yesterday, none of the solutions mentioned in this (https://github.com/facebook/metro/issues/857) metro Github repository issue have not worked for me. After hours of debugging, I changed my
"metro-config": "^0.73.2"
version, to"metro-config": "0.71.3"
inpackage.json
file and it have worked! 🙂There are details in https://github.com/facebook/metro/issues/857#issuecomment-1276253449, but the summary is that this occurs when you have multiple versions of Metro in your
node_modules
. Useyarn why metro
to confirm.You shouldn’t have any
metro*
dependencies listed in your project’spackage.json
except, for non-Expo,metro-react-native-babel-preset
. Metro is a transitive dependency in React Native / Expo apps, so you don’t need to list it.Deleting those and re-running
yarn
/npm
ought to fix the problem. If not, make sure none of your dependencies incorrectly have dependencies onmetro
orreact-native
. Again,yarn why metro
should help.