gatsbyjs / gatsby

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

Situations Where gatsby-node.js wouldn't run? #13572

Closed nickreese closed 5 years ago

nickreese commented 5 years ago

Summary

We've had a gatsby install running on netlify.com for almost 2 months with no issues. In the last few days, their build process has stopped reading our gatsby-node.js file as evidenced by this simple console.log not getting printed in the build information.

To troubleshoot we’ve downloaded the netlify build image and can confirm the build completes as expected. To make sure it wasn’t env variables causing the issue we’ve also passed in all of the exact same env variables into this build.

The build process works with gatsby build locally as well.

We've tried everything and we've contacted their support who seem to have no idea why this would be happening.

All of this said, are there any specific situations where gatsby-node.js wouldn't be run by gatsby?

Relevant information

Things we've tried:

Environment (if relevant)

Netlify's build process. Gatsby-config does run, we can see the console.logs of that.

File contents (if changed)

gatsby-config.js:

plugins: [
    "gatsby-plugin-styled-components",
    "gatsby-plugin-react-helmet",
    "gatsby-plugin-offline",

    {
      resolve: `gatsby-plugin-sitemap`,
      options: {
        output: sitemapLocation,
        // Exclude specific pages or groups of pages using glob parameters
        // See: https://github.com/isaacs/minimatch
        // The example below will exclude the single `path/to/page` and all routes beginning with `category`
        // exclude: ["/category/*", `/path/to/page`],
        exclude: ["/404/"],
        query: `
          {
            site {
              siteMetadata {
                siteUrl
              }
            }
            allSitePage {
              edges {
                node {
                  path
                }
              }
            }
        }`,
      },
    },
    {
      resolve: `gatsby-plugin-favicon`,
      options: {
        logo: "./src/images/favicon.png",

        // WebApp Manifest Configuration
        appName: null, // Inferred with your package.json
        appDescription: null,
        developerName: null,
        developerURL: null,
        dir: "auto",
        lang: "en-US",
        background: "#fff",
        theme_color: "#fff",
        display: "standalone",
        orientation: "any",
        start_url: "/?homescreen=1",
        version: "1.1",

        icons: {
          android: true,
          appleIcon: true,
          appleStartup: true,
          coast: false,
          favicons: true,
          firefox: true,
          opengraph: false,
          twitter: false,
          yandex: false,
          windows: false,
        },
      },
    },
    {
      resolve: "gatsby-plugin-robots-txt",
      options: {
        host: siteUrl,
        sitemap: siteUrl + sitemapLocation,
        env: {
          development: {
            policy: [{ userAgent: "*", disallow: ["/"] }],
          },
          production: {
            policy: [{ userAgent: "*", allow: "/" }],
          },
        },
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `imgs`,
        path: `${__dirname}/src/img`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/img`,
      },
    },
    {
      resolve: "gatsby-source-filesystem",
      options: {
        path: `${__dirname}/src/pages`,
        name: "pages",
      },
    },
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: "gatsby-starter-default",
        short_name: "starter",
        start_url: "/",
        background_color: "#663399",
        theme_color: "#663399",
        display: "minimal-ui",
        icon: "src/images/gatsby-icon.png", // This path is relative to the root of the site.
      },
    },
    {
      resolve: "gatsby-source-graphql",
      options: {
        typeName: "Postgres",
        fieldName: "postgres",
        url: process.env.GRAPHQL_URL,
        headers: {
          Authorization: `Bearer ${process.env.GRAPHQL_KEY}`,
        },
      },
    },
    "gatsby-plugin-netlify-cache",
    `gatsby-plugin-netlify`,
  ],

package.json:

"dependencies": {
    "@svg-maps/usa": "^1.0.0",
    "apollo-cache-inmemory": "^1.5.1",
    "apollo-client": "^2.5.1",
    "apollo-link-context": "^1.0.17",
    "apollo-link-http": "^1.5.14",
    "axios": "^0.18.0",
    "babel-plugin-styled-components": "^1.10.0",
    "dayjs": "^1.8.12",
    "dotenv": "^6.2.0",
    "escape-html": "^1.0.3",
    "fs": "^0.0.1-security",
    "fs-extra": "^7.0.1",
    "gatsby": "^2.0.19",
    "gatsby-cli": "^2.5.9",
    "gatsby-plugin-favicon": "^3.1.6",
    "gatsby-plugin-manifest": "^2.0.29",
    "gatsby-plugin-netlify": "^2.0.6",
    "gatsby-plugin-netlify-cache": "^1.0.0",
    "gatsby-plugin-offline": "^2.0.5",
    "gatsby-plugin-react-helmet": "^3.0.0",
    "gatsby-plugin-robots-txt": "^1.4.0",
    "gatsby-plugin-sitemap": "^2.0.5",
    "gatsby-plugin-styled-components": "^3.0.7",
    "gatsby-source-filesystem": "^2.0.4",
    "gatsby-source-graphql": "^2.0.17",
    "gatsby-source-prismic": "^2.3.0-alpha.2",
    "graphql": "^14.2.1",
    "graphql-tag": "^2.10.1",
    "lodash": "^4.17.11",
    "meta-shortcodes": "nickreese/meta-shortcodes",
    "moment": "^2.24.0",
    "path-exists": "^4.0.0",
    "polished": "^3.0.3",
    "prismic-dom": "^2.1.0",
    "prismic-helpers": "^1.0.0",
    "prismic-javascript": "^2.0.1",
    "prismic-reactjs": "^0.3.2",
    "prismic-richtext": "^1.0.0",
    "react": "^16.8.5",
    "react-apollo": "^2.5.4",
    "react-dom": "^16.8.5",
    "react-helmet": "^5.2.0",
    "react-icons": "^3.5.0",
    "react-process-string": "^1.2.0",
    "react-remarkable": "^1.1.3",
    "react-scrollchor": "^6.0.0",
    "react-simple-maps": "^0.12.1",
    "react-svg-map": "^2.0.0",
    "request-promise": "^4.2.4",
    "sharp": "0.21.3",
    "styled-components": "^4.1.3",
    "styled-normalize": "^8.0.6",
    "typeface-chivo": "^0.0.72",
    "typeface-zilla-slab": "^0.0.72",
    "webpack": "^4.30.0"
  },
  "keywords": [
    "gatsby"
  ],
  "scripts": {
    "develop": "gatsby develop",
    "start": "npm run dev",
    "start:app": "node --max_old_space_size=8192 ./node_modules/.bin/gatsby develop",
    "start:lambda": "netlify-lambda serve src/lambda",
    "dev": "node --max_old_space_size=8192 ./node_modules/.bin/gatsby develop",
    "build": "node --max_old_space_size=8192 ./node_modules/.bin/gatsby build",
    "build:app": "node --max_old_space_size=8192 ./node_modules/.bin/gatsby build",
    "build:lambda": "netlify-lambda build src/lambda",
    "test": "jest",
    "netlifybuild": "node --max_old_space_size=8192 ./node_modules/.bin/gatsby build",
    "content": "node --max-old-space-size=2000 node_modules/gatsby/dist/bin/gatsby.js develop"
  },
  "devDependencies": {
    "http-proxy-middleware": "^0.19.1",
    "jest": "^24.1.0",
    "jest-cli": "^23.3.0",
    "netlify-lambda": "^1.3.3",
    "npm-run-all": "^4.1.5",
    "prettier": "^1.14.2"
  },

gatsby-node.js:


console.log(`Hello from gatsby-node.js`)

exports.createPages = async ({ graphql, cache, actions: { createPage, createRedirect }, reporter }) => {
// biz logic
}

gatsby-browser.js: N/A gatsby-ssr.js: N/A

pieh commented 5 years ago

Just to verify, I deployed some site on Netlify and gatsby-node worked there - but this was using some vanilla options.

There is potential that there were some errors that until recently Gatsby would silently swallow so users wouldn't be notified about (it was fixed in gatsby@2.3.26 - so please try bumping to this one and see if there is any new insight showing)

If this does not help, I don't think of anything and probably won't be able to debug without access to reproduction.

nickreese commented 5 years ago

@Pieh — Got it building again for our deadline.

Will confirm what the root cause was once we sort it out. The fix was either upgrading our packages as you mentioned or resolving a conflict between two plugins. Will confirm tomorrow when back in the office so see if I can get it to fail with the plugin conflict.

Plugin conflict doesn’t make sense because it wasn’t building without ANY plugins but that was part of the same commit as upgrading dependencies so will look closer.

nickreese commented 5 years ago

@pieh — We were unable to reproduce the issue when enabling both plugins. Our team believes it was fixed by upgrading our packages including gatsby.