3

I'm working with react-native, and trying to load Apollo from apollo-boost. When I attempt to import the client, I get the error message "Attempted to assign to readonly property." I'm not sure how to work around this, and it seems from the stack trace that it's in the apollo-boost package. Anybody know how I can work around this? full stack trace

edit: Adding picture and details. I'm getting this when I try to load the app through Expo. Right when it starts, I get this. The first file in my app the stack trace mentions, StoresScreens, the line in question is only the import line.

import ApolloClient from 'apollo-boost';
psion
  • 748
  • 1
  • 6
  • 17
  • Please edit your question to include the full error and the whole stack trace you're seeing. Also, it may be helpful to describe when you encounter this error -- on initiating the client? When running a specific query or mutation? – Daniel Rearden May 22 '19 at 19:23
  • I got the same error, just with the basic initialization of Apollo Client in my React Native App – Théo Lavaux May 23 '19 at 10:24
  • Same here, just importing the module in my react-native app seems to cause this. – HendrikPetertje May 23 '19 at 11:41

2 Answers2

4

I got the same error. Solved by using apollo-client, apollo-cache-inmemory, apollo-link-http package for creating Apollo client instead of using apollo-boost.

Here's the code App.js

import React from 'react'
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

const withProvider = (Component) => {

  const cache = new InMemoryCache();
  const link = new HttpLink({
    uri: 'your-url'
  })
  const client = new ApolloClient({
    link,
    cache
  });
  return class extends React.Component {
    render() {
      return (
        <ApolloProvider client={client}>
          <Component {...this.props} client={client} />
        </ApolloProvider>
      )
    }
  }
}
export default withProvider(App);
  • 2
    Some background: this is usually caused by bundler config not being setup to compile TypeScript - which `apollo-boost` is written in. [Apollo has a handy migration guide for moving away from boost](My lazy solution was to just drop boost and manually add in the code as per the [apollo-boost migration guide](https://www.apollographql.com/docs/react/advanced/boost-migration). – Tom Walters May 24 '19 at 19:47
1

At least using Typescript, as temporary workaround you can do:

import ApolloClient from "apollo-boost/lib/index";

Seems related with this issue: https://github.com/apollographql/apollo-client/issues/4843

alexojegu
  • 754
  • 7
  • 21