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

cannot use with Expo (React Native), throws undefined for InMemoryCache #10719

Closed
zdnk opened this issue Apr 4, 2023 · 2 comments
Closed

cannot use with Expo (React Native), throws undefined for InMemoryCache #10719

zdnk opened this issue Apr 4, 2023 · 2 comments

Comments

@zdnk
Copy link

zdnk commented Apr 4, 2023

Issue Description

Hello,

I am unable to use Apollo Client in Expo application. Whatever I am trying it says some functions or classes are undefined.
IMG_585A67E75881-1

Link to Reproduction

https://snack.expo.dev/@zdnk/grounded-ramen

Reproduction Steps

install @apollo/client in Expo app
try to instantiate ApolloClient with InMemoryCache

@alessbell
Copy link
Member

Hi @zdnk 👋

It looks like the metro bundler needs additional configuration in order to implicitly resolve files with the .cjs extension (see facebook/metro#535 (comment)).

You can change your import statement to import { ApolloClient, InMemoryCache } from '@apollo/client/main.cjs';, or you can configure config.resolver.sourceExts in metro.config.js so that import { ApolloClient, InMemoryCache } from '@apollo/client'; can be resolved.

After npm installing @expo/metro-config, I was able to get the grounded-ramen app running with the following config:

const { getDefaultConfig } = require('@expo/metro-config');

const config = getDefaultConfig(__dirname);

config.resolver.sourceExts.push(
  'cjs'
);

module.exports = config;

Hope that helps! Happy hacking :)

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

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

No branches or pull requests

2 participants