How do I debug this error: `error: Error: resolveDependencies: Found duplicate dependency key 'undefined' in <local path to metro bundler>` - RN 0.70
Asked Answered
M

3

6

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.

Matsumoto answered 20/10, 2022 at 14:30 Comment(0)
H
3

It is known problem, try to follow instructions from metro GitHub repository for this issue https://github.com/facebook/metro/issues/857

Haemo answered 20/10, 2022 at 17:37 Comment(0)
W
2

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" in package.json file and it have worked! :)

Wersh answered 25/10, 2022 at 6:16 Comment(0)
B
2

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. Use yarn why metro to confirm.

You shouldn’t have any metro* dependencies listed in your project’s package.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 on metro or react-native. Again, yarn why metro should help.

Barrettbarrette answered 1/3, 2023 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.