jbolda / gatsby-source-airtable

MIT License
216 stars 43 forks source link

Crashes when "Flattening Child Nodes" #7

Closed youmustfight closed 6 years ago

youmustfight commented 6 years ago

I have a GatsbyJS project that is solely using Airtable at the moment, and during build I am able to fetch the data, but it immediately throws this error on the step that follows which I believe is build:

...
12:49:49 AM: success onPreBootstrap — 0.672 s
12:49:49 AM: success delete html and css files from previous builds — 0.104 s
12:49:49 AM: success copy gatsby files — 0.016 s
12:49:50 AM: fetch all Airtable rows from 1 tables: 536.460ms
12:49:50 AM: error Plugin gatsby-source-airtable returned an error
12:49:50 AM: 
12:49:50 AM:   TypeError: Promise.all(...).reduce is not a function
12:49:50 AM:   
12:49:50 AM:   - gatsby-node.js:115 Object.exports.sourceNodes
12:49:50 AM:     [repo]/[gatsby-source-airtable]/gatsby-node.js:115:59
12:49:50 AM:   
12:49:50 AM:   
12:49:50 AM:   - next_tick.js:189 process._tickCallback
12:49:50 AM:     internal/process/next_tick.js:189:7
12:49:50 AM:   
12:49:50 AM: 
12:49:50 AM: error Command failed with exit code 1.
12:49:50 AM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:49:50 AM: Caching artifacts
12:49:50 AM: Started saving node modules
...
12:49:50 AM: Error running command: Build script returned non-zero exit code: 1
12:49:50 AM: Failing build: Failed to build site
12:49:50 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
12:49:50 AM: Finished processing build request in 45.602681982s

This seems to have occurred both when I had no data being fetched and when I did, so I changed line number 115 in gatsby-node.js

let flattenedChildNodes = await Promise.all(childNodes).reduce(
    (accumulator, currentValue) => accumulator.concat(currentValue),
    []
);

to

let flattenedChildNodes = await Promise.all(childNodes).then(nodes => nodes.reduce(
    (accumulator, currentValue) => accumulator.concat(currentValue),
    []
));

and it works fine now. Some versions details:

"node": 8.12.0 "gatsby": "next", "gatsby-source-airtable": "^2.0.0-beta.1",

jbolda commented 6 years ago

Would you be able to share anything about your data structure? Ideally, I would like to add this situation to the example in this so we can reproduce the error and then test against it.

youmustfight commented 6 years ago

Sure! Here's the table & view that I'm playing with name: short text url: url status: single select of 'toDo'/'haveDone' type: single select of 'cooking'/'read'/'listen' attachment: attachment createdAt: date doneAt: date

image

jbolda commented 6 years ago

Not having much like reproducing (and my main dev box is barely treading water at this point 😢 ). Do you have the availability to PR an example in the repo? I can copy whatever base you come up with into my personal airtable which travis-ci is hooked up to.

jbolda commented 6 years ago

@youmustfight published a new release, would appreciate a test on your add as I wasn't able to reproduce the issue. Hopefully your issue is fixed and thanks for the PR!