Search code examples
reactjscontentful

Contentful doesn't initiate the request


I am starting with Contentful and I am getting this error.

Import error, can't find file:
./zlib_bindings

I didn't do anything I just started a request as described in docs.

This is the code till componentDidMount function. I reviewed space id and access token in my application.

import React, { Component } from 'react';
import { render } from 'react-dom';
import contentful from 'contentful'

import './style.css';
import 'bulma/css/bulma.css'

import SearchComponent from './components/SearchComponent'
import ProductSection from './components/productSection'


class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React'
    };
  }

  componentDidMount() {

    var client = contentful.createClient({
      space: 'space_ID_here',
      accessToken: 'access_here'
    })


    // This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
    client.getEntries()
      .then(function (entries) {
        // log the title for all the entries that have it
        entries.items.forEach(function (entry) {
          if (entry.fields.productName) {
            console.log(entry.fields.productName)
          }
        })
      })


  }

Solution

  • This is very odd... I checked the stackblitz link and it's also asking for installing http as a dependency which it shouldn't need. I'm almost sure that zlib_bindings is nothing related to the contentful sdk but rather something else is going on in Stackblitz or the environment you're running.

    You can find a running example in react here.