React--Native: Metro has encounter an error: While trying to resolve module
See original GitHub issueMetro 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
GSEventRunModal -[UIApplication _run] UIApplicationMain main start
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5
Workaround until fix :
Add cjs extension in metro.config.js
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’], };