question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React--Native: Metro has encounter an error: While trying to resolve module

See original GitHub issue

Metro has encountered an error: While trying to resolve module @apollo/client from file /Users/admin/Documents/MySelf/Projects/React-Native/Latest/MyProj/index.js, the package /Users/admin/Documents/MySelf/Projects/React-Native/Latest/MyProf/node_modules/@apollo/client/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/Users/admin/Documents/MySelf/Projects/React-Native/Latest/MyProf/node_modules/@apollo/client/main.cjs. Indeed, none of these files exist:

  • /Users/admin/Documents/MySelf/Projects/React-Native/Latest/MyProj/node_modules/@apollo/client/main.cjs(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  • /Users/admin/Documents/MySelf/Projects/React-Native/Latest/MyProj/node_modules/@apollo/client/main.cjs/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)

RCTFatal __28-[RCTCxxBridge handleError:]_block_invoke _dispatch_call_block_and_release _dispatch_client_callout _dispatch_main_queue_callback_4CF CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE __CFRunLoopRun CFRunLoopRunSpecific Screen Shot 2021-11-25 at 1 48 05 PM

GSEventRunModal -[UIApplication _run] UIApplicationMain main start

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

3reactions
azukencommented, Nov 25, 2021

Workaround until fix :

Add cjs extension in metro.config.js

module.exports = (() => {
  return {
    resolver: {
      sourceExts: ['cjs'],
    },
  }
})()
2reactions
pramodpariharPKcommented, Nov 26, 2021

Thanks All: Added metro-config.js file in the root folder with the below content, and it WORKED!!!..

const {getDefaultConfig} = require(‘metro-config’); const {resolver: defaultResolver} = getDefaultConfig.getDefaultValues(); exports.resolver = { …defaultResolver, sourceExts: […defaultResolver.sourceExts, ‘cjs’], };

Read more comments on GitHub >

github_iconTop Results From Across the Web

Metro bundler encountered an error while trying to resolve ...
js , the package /Users/akumar/Documents/ReactPractice/ImageSample/node_modules/react-native-camera/package.json was successfully found. However ...
Read more >
While trying to resolve module 'firebase' - Stack Overflow
I encountered the same issue with my React Native app build with expo //package.json "expo": "^44.0.0", "firebase": "^9.8.1", Metro has ...
Read more >
Error: While trying to resolve module `idb` from file React ...
Error : While trying to resolve module `idb` from filePlease do like share and comment if you like the video please do hit...
Read more >
InternalError Metro has encountered an error: While trying to ...
Everytime I install a package for the app. I get this error “InternalError Metro has encountered an error: While trying to resolve module” ......
Read more >
Troubleshooting - React Navigation
Missing extensions in metro configuration​. Sometimes the error may look like this: Error: While trying to resolve module "@react-navigation/native" from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found