Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pramodpariharPK opened this issue Nov 25, 2021 · 5 comments

Comments

@pramodpariharPK
Copy link

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

@param-finder
Copy link

param-finder commented Nov 25, 2021

Same error!

@azuken
Copy link

azuken commented Nov 25, 2021

Workaround until fix :

Add cjs extension in metro.config.js

module.exports = (() => {
  return {
    resolver: {
      sourceExts: ['cjs'],
    },
  }
})()

@param-finder
Copy link

Yeah, found this in changelog.
https://github.com/apollographql/apollo-client/blob/v3.5.5/CHANGELOG.md#apollo-client-354-2021-11-19

@almsx

This comment has been minimized.

@pramodpariharPK
Copy link
Author

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'],
};

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants