满意不会发起请求

时间:2018-11-12 09:38:52

标签: reactjs contentful

我从Contentful开始,出现此错误。

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

我没有做任何事情,只是按照文档中的描述开始了一个请求。

这是直到componentDidMount函数的代码。 我查看了空间ID和访问令牌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)
          }
        })
      })


  }

1 个答案:

答案 0 :(得分:1)

这很奇怪...我检查了stackblitz链接,它还要求安装http作为不需要的依赖项。我几乎可以肯定zlib_bindingsnothing related to the contentful sdk,但是Stackblitz或您正在运行的环境中正在发生其他事情。

您可以在react here中找到正在运行的示例。