본문 바로가기
Coding/React

React Native - While trying to resolve module `@apollo/client` from file

by z쿳쿳z 2022. 4. 2.
728x90
반응형

React Native에서 graphql을 setting을 하면서 While trying to resolve module `@apollo/client` from file  error가 발생 할 수 있다. 

@apollo/client 버전이 3.5 이상이 되면서 .cjs 파일을 읽지 못해서 생기는 원인이다. 

이것을 해결 하기 위해서는 root 디렉토리에 metro.config.js 파일을 만들고 다음과 같이 설정을 해주면 된다.

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

설정하고 나서 다시 bundle을 시키면 잘 작동한다.

 

참조

https://github.com/apollographql/apollo-client/releases/tag/v3.5.4

 

Release 3.5.x · apollographql/apollo-client

Apollo Client 3.5.5 (2021-11-23) Bug Fixes Remove printer: Printer positional parameter from publicly-exported selectHttpOptionsAndBody function, whose addition in #8699 was a breaking change (sta...

github.com

https://microeducate.tech/main-module-field-cannot-be-resolved-after-installing-apollo-client/

 

Main module field cannot be resolved after installing @apollo/client - MicroEducate

I’m running into an error after installing Apollo when trying to run my React Native Expo app. I’ve tried deleting node-modules and re-installing, resetting cache, restarting computer, and still no luck. Android Bundling failed 456ms While trying to re

microeducate.tech

 

728x90
반응형