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

Server Side Rendering with Apollo Client #1045

Closed
hin101 opened this issue Dec 23, 2019 · 2 comments
Closed

Server Side Rendering with Apollo Client #1045

hin101 opened this issue Dec 23, 2019 · 2 comments

Comments

@hin101
Copy link

hin101 commented Dec 23, 2019

I am getting the following error when I try to server side render with Apollo Client. It works fine on the client side:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.>"

Steps to reproduce

Expected behavior

Should server side render fine

Actual behavior

PostContentBuilderApp.js

import React from 'react';
import AppContext from '../utilities/appContext';
import PostContentBuilder from "./PostContentBuilder/components/PostContentBuilder";
import { ApolloProvider } from '@apollo/react-hooks';
import { client } from './PostContentBuilder/utils/client';

const postContentBuilderApp = (props) => {
  return(
  <AppContext.Provider
    value={{
      propsFromRails: props,
    }}
  >
    <ApolloProvider client={client}>
      <PostContentBuilder />
    </ApolloProvider>
  </AppContext.Provider>
  )
};

export default postContentBuilderApp;

client.js

import fetch from 'node-fetch';
import ApolloClient from 'apollo-boost';
import { typeDefs } from './resolvers';

export const client = new ApolloClient({
    fetch: fetch,
    clientState: {
      typeDefs,
    },
  });

resolvers.js

export const typeDefs = `
  type NewCmsComponentEntityInput!{
    arguments: {
      name: String,
      position: Int,
      parentId: ID,
      cmsPageId: ID
    }
  }
`;
@LauraAubin
Copy link

LauraAubin commented Dec 24, 2019

I'm seeing this too when I try to render my component from a controller. I have to turn prerender off to get around the error,

render component: 'Home', props: {}, prerender: false

@hin101
Copy link
Author

hin101 commented Dec 24, 2019

I worked out what it was, we have to import whatwg-fetch in our entry point.

Issue #264 helped me debug this.

@hin101 hin101 closed this as completed Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants