apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

app crash after apollo client update

Open AlexandrBol opened this issue 3 years ago • 7 comments

After updatig @apollo/client from version 3.4.14 to version 3.6.2 I got this error

Metro has encountered an error: While trying to resolve module `@apollo/client` from file `my-path/App.tsx`, the package `my-path/node_modules/@apollo/client/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`my-path/node_modules/@apollo/client/main.cjs`. Indeed, none of these files exist:

  * /my-path/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)
  * my-path/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): /my-path/node_modules/metro/src/node-haste/DependencyGraph.js (243:17)

  241 | 
  242 |         if (error instanceof InvalidPackageError) {
> 243 |           throw new PackageResolutionError({
      |                 ^
  244 |             packageError: error,
  245 |             originModulePath: from,
  246 |             targetModuleName: to,

RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start_sim
0x0

I was trying to update metro config with:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */
const {getDefaultConfig} = require('metro-config');
const {resolver: defaultResolver} = getDefaultConfig.getDefaultValues();

module.exports = {
  resolver: {
    ...defaultResolver,
    sourceExts: [...defaultResolver.sourceExts, 'cjs'],
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};

but got no success

AlexandrBol avatar May 16 '22 11:05 AlexandrBol

@AlexandrBol Can you try npm i @apollo/client@beta to find out if #9716 solves this problem for you?

benjamn avatar May 16 '22 18:05 benjamn

@benjamn after using @apollo/client@beta got this error on app open image

AlexandrBol avatar May 17 '22 15:05 AlexandrBol

@AlexandrBol That's at least a different (runtime) problem, so we're making progress!

benjamn avatar May 17 '22 15:05 benjamn

What versions of react/react-dom and react-native are you using? I ask because I don't think React Native is yet compatible with React 18, in case you tried upgrading.

benjamn avatar May 17 '22 15:05 benjamn

He is using the following: @benjamn

    "react-native": "0.68.0",
   "@apollo/client": "3.4.14",
    "@apollo/react-hooks": "^4.0.0",
    "react": "18.0.0", // so that is the culprit

6ewis avatar May 19 '22 07:05 6ewis

@benjamn @6ewis So, I tested once again

    "react": "18.0.0",
    "react-native": "0.68.0",

with "@apollo/client": "3.4.14", all working pretty good, but with "@apollo/client": "^3.7.0-alpha.6" - no

I was trying to add react-dom (test that all works good) and then add "@apollo/client": "^3.7.0-alpha.6" - got no result still same issue as

image

Upd: So, I mean that the trouble not is in the react/react-native/react-dom. Trouble inside lib

AlexandrBol avatar May 24 '22 10:05 AlexandrBol

@benjamn it seems that react 18 is now compatible with react native. So the issue might be somewhere else

6ewis avatar May 26 '22 12:05 6ewis