gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

Gatsby-source-contentful throws build error #28804

Closed imnotdannorton closed 3 years ago

imnotdannorton commented 3 years ago

Description

Published asset in Contentful not being recognized in Gatsby build process

Steps to reproduce

Using Contentful as a data source, remove an asset from an entry, then upload a new asset and attach it to the entry. Then run a build.

Expected result

Gatsby should fetch new entry data from contentful with the updated asset and build.

Actual result

Gatsby attempts to find the asset in the contentful cache(?) but fails. Logs below:


12:10:13 PM:   Netlify Build                                                 
12:10:13 PM: ────────────────────────────────────────────────────────────────
12:10:13 PM: ​
12:10:13 PM: ❯ Version
12:10:13 PM:   @netlify/build 8.0.0
12:10:13 PM: ​
12:10:13 PM: ❯ Flags
12:10:13 PM:   deployId: 5fecb41068b8540140a546e2
12:10:13 PM:   mode: buildbot
12:10:13 PM: ​
12:10:13 PM: ❯ Current directory
12:10:13 PM:   /opt/build/repo
12:10:13 PM: ​
12:10:13 PM: ❯ Config file
12:10:13 PM:   /opt/build/repo/netlify.toml
12:10:13 PM: ​
12:10:13 PM: ❯ Context
12:10:13 PM:   production
12:10:13 PM: ​
12:10:13 PM: ❯ Installing plugins
12:10:13 PM:    - netlify-plugin-gatsby-cache@0.3.0
12:10:14 PM: ​
12:10:14 PM: ❯ Loading plugins
12:10:14 PM:    - netlify-plugin-gatsby-cache@0.3.0 from netlify.toml
12:10:14 PM: ​
12:10:14 PM: ────────────────────────────────────────────────────────────────
12:10:14 PM:   1. onPreBuild command from netlify-plugin-gatsby-cache        
12:10:14 PM: ────────────────────────────────────────────────────────────────
12:10:14 PM: ​
12:10:14 PM: No Gatsby cache found. Building fresh.
12:10:14 PM: ​
12:10:14 PM: (netlify-plugin-gatsby-cache onPreBuild completed in 159ms)
12:10:14 PM: ​
12:10:14 PM: ────────────────────────────────────────────────────────────────
12:10:14 PM:   2. Build command from Netlify app                             
12:10:14 PM: ────────────────────────────────────────────────────────────────
12:10:14 PM: ​
12:10:14 PM: $ npm run build
12:10:15 PM: > gatsby-starter-default@0.1.0 build /opt/build/repo
12:10:15 PM: > GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true gatsby build --log-pages
12:10:17 PM: success open and validate gatsby-configs - 0.069s
12:10:18 PM: success load plugins - 0.849s
12:10:18 PM: success onPreInit - 0.011s
12:10:18 PM: success initialize cache - 0.007s
12:10:18 PM: success copy gatsby files - 0.034s
12:10:18 PM: success onPreBootstrap - 0.009s
12:10:19 PM: success createSchemaCustomization - 0.006s
12:10:19 PM: Starting to fetch data from Contentful
12:10:19 PM: info Fetching default locale
12:10:19 PM: info default locale is: en-US
12:10:34 PM: info contentTypes fetched 39
12:10:34 PM: info Updated entries 4514
12:10:34 PM: info Deleted entries 0
12:10:34 PM: info Updated assets 389
12:10:34 PM: info Deleted assets 0
12:10:34 PM: Fetch Contentful data: 14986.563ms
12:10:43 PM: success Checking for changed pages - 0.000s
12:10:43 PM: success source and transform nodes - 24.550s
12:10:47 PM: success building schema - 4.100s
12:10:49 PM: error "gatsby-node.js" threw an error while running the createPages lifecycle:
12:10:49 PM: ENOENT: no such file or directory, open '/opt/build/repo/.cache/contentful/assets/dunkinbrands-57b9a66b25efd079b9b055153ca110f8.jpg'
12:10:49 PM: 
12:10:49 PM: 
12:10:49 PM:   Error: ENOENT: no such file or directory, open '/opt/build/repo/.cache/content  ful/assets/dunkinbrands-57b9a66b25efd079b9b055153ca110f8.jpg'
12:10:49 PM: 
12:10:49 PM: failed createPages - 1.409s
12:10:49 PM: npm ERR! code ELIFECYCLE
12:10:49 PM: npm ERR! errno 1
12:10:49 PM: npm ERR! gatsby-starter-default@0.1.0 build: `GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true gatsby build --log-pages`
12:10:49 PM: npm ERR! Exit status 1
12:10:49 PM: npm ERR!
12:10:49 PM: npm ERR! Failed at the gatsby-starter-default@0.1.0 build script.
12:10:49 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
12:10:49 PM: npm ERR! A complete log of this run can be found in:
12:10:49 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-12-30T17_10_49_144Z-debug.log
12:10:49 PM: ​
12:10:49 PM: ────────────────────────────────────────────────────────────────
12:10:49 PM:   "build.command" failed                                        
12:10:49 PM: ────────────────────────────────────────────────────────────────
12:10:49 PM: ​
12:10:49 PM:   Error message
12:10:49 PM:   Command failed with exit code 1: npm run build
12:10:49 PM: ​
12:10:49 PM:   Error location
12:10:49 PM:   In Build command from Netlify app:
12:10:49 PM:   npm run build
12:10:49 PM: ​
12:10:49 PM:   Resolved config
12:10:49 PM:   build:
12:10:49 PM:     command: npm run build
12:10:49 PM:     commandOrigin: ui
12:10:49 PM:     environment:
12:10:49 PM:       - BCOV_POLICY
12:10:49 PM:       - CONTENTFUL_ACCESS_TOKEN
12:10:49 PM:       - ENVIRONMENT
12:10:49 PM:       - GATSBY_CONTENTFUL_ACCESS_TOKEN
12:10:49 PM:     functions: /opt/build/repo/functions
12:10:49 PM:     publish: /opt/build/repo/public
12:10:49 PM:   plugins:
12:10:49 PM:     - inputs: {}
12:10:49 PM:       origin: config
12:10:49 PM:       package: netlify-plugin-gatsby-cache
12:10:49 PM: Caching artifacts
12:10:49 PM: Started saving node modules
12:10:49 PM: Finished saving node modules
12:10:49 PM: Started saving build plugins
12:10:49 PM: Finished saving build plugins
12:10:49 PM: Started saving yarn cache
12:10:49 PM: Finished saving yarn cache
12:10:49 PM: Started saving pip cache
12:10:49 PM: Finished saving pip cache
12:10:49 PM: Started saving emacs cask dependencies
12:10:49 PM: Finished saving emacs cask dependencies
12:10:49 PM: Started saving maven dependencies
12:10:49 PM: Finished saving maven dependencies
12:10:49 PM: Started saving boot dependencies
12:10:49 PM: Finished saving boot dependencies
12:10:49 PM: Started saving rust rustup cache
12:10:49 PM: Finished saving rust rustup cache
12:10:49 PM: Started saving rust cargo bin cache
12:10:49 PM: Finished saving rust cargo bin cache
12:10:49 PM: Started saving go dependencies
12:10:50 PM: Finished saving go dependencies
12:10:53 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:10:53 PM: Failing build: Failed to build site
12:10:53 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:10:53 PM: Finished processing build request in 2m19.766222655s```

### Environment

Netlify.

```"dependencies": {
    "@brightcove/react-player-loader": "^1.4.0",
    "@contentful/rich-text-from-markdown": "^13.4.0",
    "@contentful/rich-text-html-renderer": "^13.4.0",
    "@contentful/rich-text-react-renderer": "^13.4.0",
    "@elastic/react-search-ui": "^1.3.2",
    "@elastic/search-ui-app-search-connector": "^1.3.2",
    "axios": "^0.19.2",
    "axios-cookiejar-support": "^1.0.0",
    "contentful": "^7.14.5",
    "cookie": "^0.4.1",
    "core-js": "^3.6.5",
    "dotenv": "^8.2.0",
    "form-data": "^3.0.0",
    "gatsby": "^2.23.12",
    "gatsby-cli": "^2.12.67",
    "gatsby-image": "^2.4.9",
    "gatsby-plugin-canonical-urls": "^2.1.20",
    "gatsby-plugin-create-client-paths": "^2.3.9",
    "gatsby-plugin-google-tagmanager": "^2.3.15",
    "gatsby-plugin-manifest": "^2.4.14",
    "gatsby-plugin-netlify": "^2.3.9",
    "gatsby-plugin-offline": "^3.2.13",
    "gatsby-plugin-polyfill-io": "^1.1.0",
    "gatsby-plugin-react-helmet": "^3.3.6",
    "gatsby-plugin-react-i18next": "^0.0.25",
    "gatsby-plugin-sass": "^2.1.29",
    "gatsby-plugin-sharp": "^2.6.14",
    "gatsby-plugin-sitemap": "^2.2.27",
    "gatsby-source-contentful": "^2.1.86",
    "gatsby-source-filesystem": "^2.3.14",
    "gatsby-transformer-sharp": "^2.5.7",
    "i18next": "^19.7.0",
    "imagemin-pngquant": "^5.0.1",
    "intersection-observer": "^0.11.0",
    "js-cookie": "^2.2.1",
    "js-yaml": "^3.13.1",
    "lodash": "^4.17.20",
    "markdown-to-jsx": "^6.11.4",
    "node-fetch": "^2.6.0",
    "node-sass": "^4.13.1",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-google-maps": "^9.4.5",
    "react-grid-system": "^7.0.3",
    "react-helmet": "^5.2.1",
    "react-i18next": "^11.7.2",
    "react-intersection-observer": "^8.30.3",
    "react-lazyload": "^3.1.0",
    "react-lottie": "^1.2.3",
    "react-parallax": "^3.0.3",
    "react-scroll-parallax": "^2.3.1",
    "react-scrolllock": "^5.0.1",
    "react-share": "^4.3.1",
    "react-spring": "^8.0.27",
    "react-touch-carousel": "^0.9.3",
    "request-promise": "^4.2.5",
    "sharp": "^0.24.1",
    "tough-cookie": "^4.0.0"
  }```

To be honest I am not sure if the issue here is Gatsby or contentful. Seems that the `npm run build` process that triggers the Gatsby build is what is not finding the asset. Has anyone seen this issue before? I tried updating the entry with different file formats and kept getting the same error. Looking for at least some advice to troubleshoot. Does not happen on local build.
LekoArts commented 3 years ago

Hi!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

LekoArts commented 3 years ago

Hi!

Since we didn't receive an answer for 7 business days or more about the ask of a reproduction I'm going to close this now, as we can't do much to help without a reproduction. If you are able to create a minimal reproduction for this then please do answer here or reopen the issue. Thanks!