close

[Solved] While trying to resolve module @apollo/client from file

Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to run my react native app But I am facing following error While trying to resolve module @apollo/client from file in React Native. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How While trying to resolve module @apollo/client from file Error Occurs ?

I am trying to run my react native app But I am facing following error.

Android Bundling failed 456ms While trying to resolve module @apollo/client from file >/Users/ssc/Desktop/MyProject/App.tsx, the package >/Users/ssc/Desktop/MyProject/node_modules/@apollo/client/package.json >was successfully found. However, this package itself specifies a main module field that >could not be resolved >(/Users/ssc/Desktop/MyProject/node_modules/@apollo/client/main.cjs. Indeed, none of these files exist:

How To Solve While trying to resolve module @apollo/client from file Error ?

  1. How To Solve While trying to resolve module @apollo/client from file Error?

    To Solve While trying to resolve module @apollo/client from file Error First of Create metro.config.js file in root of your project directory and then add following code. Then Rerun your react-native app and Your error must be solved. Second solution is Just need to downgrade @apollo/client to 3.4.16 and Now, Your error must be solved.

  2. While trying to resolve module @apollo/client from file

    To Solve While trying to resolve module @apollo/client from file Error First of Create metro.config.js file in root of your project directory and then add following code. Then Rerun your react-native app and Your error must be solved. Second solution is Just need to downgrade @apollo/client to 3.4.16 and Now, Your error must be solved.

Solution 1: Create metro.config.js file

First of Create metro.config.js file in root of your project directory and then add following code.

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

Then Rerun your react-native app and Your error must be solved.

Solution 2: downgrade @apollo/client

Just need to downgrade @apollo/client to 3.4.16 and Now, Your error must be solved.

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read