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

Next.js with tabletop #6091

Closed
johnstew opened this issue Jan 19, 2019 · 1 comment
Closed

Next.js with tabletop #6091

johnstew opened this issue Jan 19, 2019 · 1 comment

Comments

@johnstew
Copy link

Bug report

Describe the bug

I'm trying to import Tabletop.js and getting some require errors around it. It appears the client bundle is looking for server side packages.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Install tabletop in Next.js project
  2. Invoke Tabletop.init(...)
  3. Run next dev
import Tabletop from 'tabletop';

function getData() {
  return new Promise(resolve => {
    Tabletop.init({
      key: 'magical-fake-key',
      callback: data => resolve(data),
      simpleSheet: true
    });
  });
}

export default class index extends React.Component {
  static async getInitialProps() {
    try {
      const data = await getData();
      if (data.length === 0) {
        console.log('Data is missing, :(');
      }
      const processedData = processData(data);
      return { cmsData: processedData };
    } catch (error) {
      console.error(error);
    }
    return { cmsData: {} };
  }

  ...
}

Expected behavior

Tabletop has a server side component and a client side component. So I think I was hoping this would work realizing that it might not 😄

Screenshots

Errors I get when trying to do this.
screen shot 2019-01-19 at 9 51 56 am

System information

  • OS: macOs
  • Version of Next.js: 7.0.2

Additional context

I got around this by creating a custom express server but I'd really love to not have to do that given that Now v2 doesn't really recommend this approach to deploy. https://spectrum.chat/?thread=ebd1f14e-cacb-48cb-9df1-97b4ceca6b87

@timneutkens
Copy link
Member

The correct way to handle this is creating an external API and fetch that API from Next.js, because Next.js will need to be able to fetch data on both the server + client side, if you use <Link> getInitialProps is executed on the client side.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants