modiimedia / contentful-hugo

A CLI tool that pulls data from Contentful and turns it into markdown files for Hugo and other static site generators. It also includes an express server that can be used for local development and content previews

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to pull any data

panzacoder opened this issue · comments

Hi there,

Apologies if I'm missing something obvious here, but I've been unable to run this successfully. I have a config file set up, but when I run this it just says

---------------------------------------------
   Pulling Published Data from Contentful...
---------------------------------------------


---------------------------------------------

I did have to run a script to replace windows-based whitespace on the executable in order to get it to run, not sure if that's related.

Hey panzacoder can you provide a copy of your config?
Also can you share more details about your environment? (OS and Node Version)

I did have to run a script to replace windows-based whitespace on the executable in order to get it to run, not sure if that's related.

Hmm the latest version runs fine on my MacBook Air. I'm wondering why you had to do this.

Oh I also just realized. In Contentful are your entries published? Or are they all still drafts? If you want to pull drafts and published content then you need to run contentful-hugo --preview since it only pulls published content by default.

Thanks for all the replies! Here's my info:
Config:

contentful:
     space: '[redacted]' # defaults to CONTENTFUL_SPACE env variable
     token: '[redacted]' # defaults to  CONTENTFUL_TOKEN env variable
     # previewToken: 'content-preview-token' # defaults to  CONTENTFUL_PREVIEW_TOKEN env variable
     environment: 'master' # defaults to "master"

repeatableTypes:
    # fetches all the entries of a content type and places them in a directory.
    # Generated files will be named after their Entry ID in Contentful.

    - id: blogPost
      directory: content/blog
      fileExtension: md
      mainContent: body
      resolveEntries: # resolves a reference or asset field to a specific property
          - field: categories
            resolveTo: fields.name
          - field: author
            resolveTo: fields.name 

Node Version: v14.11.0
OS: MacOS 11.4

The contentful instance is definitely published, I'm working on migrating frontend systems for a live site.

Attempted reinstalling the package and switching to a JS based config just in case something was formatted wrong, and got the CRLF error again. Looks like that part is related to this: yarnpkg/yarn#5480
(I typically use yarn)

Hmm I'm trying to run it with a yaml config on my machine and I get the same error. I'll try to get a patch out for that tonight.

Were you able to get it running with a JS based config?

@panzacoder I just pushed a fix for the YAML config loader. So if you update to the latest version (v1.17.2) you should be able to use YAML configs no problem.

Concerning the CRLF error with yarn I'll have to look further into that but that issue you linked seems like a good starting point. I usually use NPM so I haven't encountered that issue specifically.

The line ending issue has been fixed in v1.17.3

I tested installing with yarn on my MacBook and all seems to be well. Let me know if you have any other issues or the problem persists.

Hey there! Thanks for all the updates. I downloaded the latest version and have been having better luck with the JS config. I'm going to need that in the long run for custom entry resolvers so I'm going to leave it for now.

I am able to pull data as I would expect! I'm now getting a separate error when I add the "staticContent" option. Here's my new config:

module.exports = {
  contentful: {
    space: "[redacted]", // defaults to CONTENTFUL_SPACE env variable
    token: "[redacted]", // defaults to  CONTENTFUL_TOKEN env variable
    environment: "master",
  },
  repeatableTypes: [
    {
      id: "blogPost",
      directory: "content/blog",
      fileExtension: "md",
      mainContent: "body",
      resolveEntries: [
        {
          field: "categories",
          resolveTo: "fields.name",
        },
        {
          field: "author",
          resolveTo: "fields.name",
        },
      ],
    },
  ],
  staticContent: [
    {
      inputDir: "static_content",
      ouputDir: "content",
    },
  ],
}; 

When I run this, I get the following error message:

± npx contentful-hugo                                    rvm:(ruby-2.6.3) | node(v15.11.0)
[contentful hugo] Copying static content...
node:internal/process/promises:245
          triggerUncaughtException(err, true /* fromPromise */);
          ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:329:5)
    at validateString (node:internal/validators:129:11)
    at Object.resolve (node:path:1019:7)
    at /Users/[redacted path]/node_modules/contentful-hugo/dist/main/staticContent/fileManager.js:84:42
    at step (/Users/[redacted path]/node_modules/contentful-hugo/dist/main/staticContent/fileManager.js:33:23)
    at Object.next (/Users/[redacted path]/node_modules/contentful-hugo/dist/main/staticContent/fileManager.js:14:53)
    at fulfilled (/Users/[redacted path]/node_modules/contentful-hugo/dist/main/staticContent/fileManager.js:5:58) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Let me know if you'd like me to open this as a separate issue.

Hey @panzacoder
You have a typo in your config. ouputDir should be outputDir

btw you can add the following code right above module.exports and depending on your text editor you'll get intellisense for your config in your text editor (I use VSCode)

/**
 * @type {import('contentful-hugo').ContentfulHugoConfig}
 */

I use that a ton to help me avoid typo issues.