gatsbyjs / gatsby

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

Gatsby develop leaves .cache/json empty from version 2.24.12 #26287

Closed lorisdev closed 4 years ago

lorisdev commented 4 years ago

Description

I cannot use the gatsby develop command because it leaves an empty .cache/json folder thus the dev server cannot serve the site.

Unforunately the codebase is private but I was able identify on which gatsby version the issue occured. Gatsby 2.24.8 and 2.24.10 => OK develop works normally Gatsby 2.24.9 and 2.24.11 => develop works but output non blocking errors at the end of the script :

Error loading a result for the page query in "/dev-404-page". Query was not run and no cached result was found.
Error loading a result for the page query in "/404.html". Query was not run and no cached result was found.
Error loading a result for the page query in "/". Query was not run and no cached result was found.

From Gatsby 2.24.12 to current version 2.24.34 (I didn't test every version in between) =>.cache/json stays empty during develop script. This is the last output before crash :

success Building development bundle - 55.715s

ERROR 

ENOENT: no such file or directory, open '/Users/path/to/project/.cache/json/_...random..._page.json'

Steps to reproduce

Run gatsby develop

Expected result

The develop script run smoothly and and development server is launched at the end of the process

Actual result

The develop script runs without apparent errors but then the dev server crashes because .cache/json is empty

Environment

  System:
    OS: macOS 10.15.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.4.0 - ~/.nvm/versions/node/v14.4.0/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v14.4.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 84.0.4147.105
    Firefox: 79.0
    Safari: 13.1.2
  npmPackages:
    gatsby: ^2.24.34 => 2.24.34 
    gatsby-background-image: ^1.1.1 => 1.1.1 
    gatsby-image: ^2.4.14 => 2.4.14 
    gatsby-plugin-eslint: ^2.0.8 => 2.0.8 
    gatsby-plugin-google-tagmanager: ^2.3.11 => 2.3.11 
    gatsby-plugin-manifest: ^2.4.22 => 2.4.22 
    gatsby-plugin-material-ui: ^2.1.10 => 2.1.10 
    gatsby-plugin-node-reload: ^1.1.0 => 1.1.0 
    gatsby-plugin-offline: ^3.2.22 => 3.2.22 
    gatsby-plugin-react-helmet: ^3.3.10 => 3.3.10 
    gatsby-plugin-react-leaflet: ^2.0.13 => 2.0.13 
    gatsby-plugin-remote-images: ^2.2.0 => 2.2.0 
    gatsby-plugin-s3: ^0.3.3 => 0.3.4 
    gatsby-plugin-sass: ^2.3.12 => 2.3.12 
    gatsby-plugin-sharp: ^2.6.25 => 2.6.25 
    gatsby-plugin-typegen: ^2.2.1 => 2.2.1 
    gatsby-plugin-typescript: ^2.4.15 => 2.4.17 
    gatsby-plugin-typescript-checker: ^1.1.1 => 1.1.1 
    gatsby-source-filesystem: ^2.3.24 => 2.3.24 
    gatsby-source-graphql: ^2.7.0 => 2.7.0 
    gatsby-transformer-sharp: ^2.5.12 => 2.5.12 
  npmGlobalPackages:
    gatsby-cli: 2.12.77

Dependencies

"dependencies": {
    "@date-io/date-fns": "^1.3.13",
    "@material-ui/core": "^4.10.2",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.56",
    "@material-ui/pickers": "^3.2.10",
    "@react-hook/throttle": "^2.2.0",
    "axios": "^0.19.2",
    "babel-preset-react-app": "^9.1.1",
    "classnames": "^2.2.6",
    "date-fns": "^2.15.0",
    "date-fns-timezone": "^0.1.4",
    "deepmerge": "^4.2.2",
    "dompurify": "^2.0.11",
    "elasticsearch-browser": "^16.7.1",
    "gatsby": "^2.24.34",
    "gatsby-background-image": "^1.1.1",
    "gatsby-image": "^2.4.14",
    "gatsby-plugin-google-tagmanager": "^2.3.11",
    "gatsby-plugin-manifest": "^2.4.22",
    "gatsby-plugin-material-ui": "^2.1.10",
    "gatsby-plugin-node-reload": "^1.1.0",
    "gatsby-plugin-offline": "^3.2.22",
    "gatsby-plugin-react-helmet": "^3.3.10",
    "gatsby-plugin-react-leaflet": "^2.0.13",
    "gatsby-plugin-remote-images": "^2.2.0",
    "gatsby-plugin-s3": "^0.3.3",
    "gatsby-plugin-sass": "^2.3.12",
    "gatsby-plugin-sharp": "^2.6.25",
    "gatsby-plugin-typegen": "^2.2.1",
    "gatsby-plugin-typescript": "^2.4.15",
    "gatsby-plugin-typescript-checker": "^1.1.1",
    "gatsby-source-filesystem": "^2.3.24",
    "gatsby-source-graphql": "^2.7.0",
    "gatsby-transformer-sharp": "^2.5.12",
    "leaflet": "^1.6.0",
    "node-sass": "^4.14.1",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-helmet": "^6.1.0",
    "react-intl": "^5.4.6",
    "react-leaflet": "^2.7.0",
    "react-player": "^2.5.0",
    "slugify": "^1.4.5",
    "yup": "^0.29.3"
},
"devDependencies": {
    "@formatjs/cli": "^2.3.1",
    "@octokit/core": "^3.1.2",
    "@octokit/plugin-retry": "^3.0.3",
    "@octokit/rest": "^18.0.1",
    "@storybook/addon-actions": "^5.3.19",
    "@storybook/addon-info": "^5.3.19",
    "@storybook/addon-knobs": "^5.3.19",
    "@storybook/addon-links": "^5.3.19",
    "@storybook/addon-viewport": "^5.3.19",
    "@storybook/addons": "^5.3.19",
    "@storybook/react": "^5.3.19",
    "@types/classnames": "^2.2.10",
    "@types/dompurify": "^2.0.3",
    "@types/geojson": "^7946.0.7",
    "@types/jest": "^26.0.9",
    "@types/leaflet": "^1.5.16",
    "@types/react": "^16.9.44",
    "@types/react-dom": "^16.9.7",
    "@types/react-helmet": "^6.1.0",
    "@types/react-leaflet": "^2.5.1",
    "@types/yup": "^0.29.4",
    "@typescript-eslint/eslint-plugin": "^3.8.0",
    "babel-loader": "^8.0.6",
    "env-cmd": "^10.1.0",
    "eslint": "^7.6.0",
    "eslint-config-airbnb-typescript": "^9.0.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-loader": "^4.0.2",
    "eslint-plugin-import": "^2.21.2",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-react": "^7.20.5",
    "eslint-plugin-react-hooks": "^4.0.8",
    "gatsby-plugin-eslint": "^2.0.8",
    "husky": "^4.2.3",
    "lint-staged": "^10.2.11",
    "minimist": "^1.2.3",
    "prettier": "^2.0.5",
    "shelljs": "^0.8.4",
    "typescript": "^3.9.7"
},

Gatsby-Config

const activeEnv = process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || 'development';
require('dotenv').config({
    path: `.env.${activeEnv}`,
});

module.exports = {
    pathPrefix: '', // CircleCi Artifacts prefix
    assetPrefix: process.env.ASSET_PREFIX_URL,
    siteMetadata: {
        title: 'title',
        description: 'description',
        author: '@autho',
    },
    plugins: [
        {
            resolve: 'gatsby-plugin-google-tagmanager',
            options: {
                id: process.env.GATSBY_GTM_ID,
                includeInDevelopment: true,
            },
        },
        'gatsby-plugin-typescript',
        'gatsby-plugin-typescript-checker',
        'gatsby-plugin-node-reload',
        {
            resolve: 'gatsby-plugin-typegen',
            options: {
                emitSchema: {
                    'src/__generated__/gatsby-introspection.json': true,
                    'src/__generated__/gatsby-schema.graphql': true,
                },
                emitPluginDocuments: {
                    'src/__generated__/gatsby-plugin-documents.graphql': true,
                },
            },
        },
        {
            resolve: 'gatsby-source-graphql',
            options: {
                // Arbitrary name for the remote schema Query type
                typeName: 'GATEWAY',
                // Field under which the remote schema will be accessible. You'll use this in your Gatsby query
                fieldName: 'gateway',
                // Url to query from
                url: process.env.GATSBY_GRAPHQL_API,
            },
        },
        {
            resolve: 'gatsby-plugin-react-leaflet',
            options: {
                linkStyles: true, // (default: true) Enable/disable loading stylesheets via CDN
            },
        },
        {
            resolve: 'gatsby-plugin-eslint',
            options: {
                test: /\.js$|\.jsx$|\.ts$|\.tsx$/,
                exclude: /(node_modules|.cache|public)/,
                stages: ['develop'],
                options: {
                    emitWarning: true,
                    failOnError: true,
                },
            },
        },
        'gatsby-plugin-sass',
        'gatsby-plugin-react-helmet',
        'gatsby-plugin-material-ui-theme-provider', // Custom Plugin
        {
            resolve: 'gatsby-plugin-material-ui',
            options: {
                stylesProvider: {
                    injectFirst: true,
                },
            },
        },
        {
            resolve: 'gatsby-source-s3-asset',
            options: {
                accessKeyId: process.env.GATSBY_AWS_ACCESS_KEY,
                secretAccessKey: process.env.GATSBY_AWS_SECRET_ACCESS_KEY,
                region: process.env.GATSBY_AWS_REGION,
                bucketName: process.env.GATSBY_ASSETS_BUCKET_NAME,
                publicDomain: process.env.GATSBY_ASSETS_BUCKET_NAME,
                protocol: 'https',
                prefix: 'common',
                nodeType: 'Assets',
            },
        },
        {
            resolve: 'gatsby-plugin-s3',
            options: {
                bucketName: 'staging.domain.com',
                protocol: 'https',
                hostname: 'staging.domain.fr',
            },
        },
        {
            resolve: 'gatsby-plugin-remote-images',
            options: {
                nodeType: 'Assets',
                imagePath: 'url',
                prepareUrl: (url) => encodeURI(url),
            },
        },
        'gatsby-transformer-sharp',
        'gatsby-plugin-sharp',
        {
            resolve: 'gatsby-plugin-manifest',
            options: {
                name: 'name',
                short_name: 'short_name',
                start_url: '/',
                background_color: '#252733',
                theme_color: '#29c5a9',
                display: 'minimal-ui',
                icon: 'src/images/icon.png', // This path is relative to the root of the site.
            },
        },
    ],
};
TylerBarnes commented 4 years ago

Hi @lorisdev !

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! 💜

pascaloliv commented 4 years ago

Hello @lorisdev - did you manage to go futher until early august ? I'm facing a similar issue with my gatsby develop command right now.

  Error: ENOENT: no such file or directory, open 'path/to/my/project/.cache/json/_[some-random-page-slug].json'

Using gatsby build, I'm building correctly a 4k pages website - but on local development I'm stuck with that error. I'm suspecting maybe a long graphQL query or heavy image processing causing memory overheap or something.

Thanks in advance for any infos on this issue.

P.S: My specs

System:
    OS: macOS 10.15.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.16.1 - /var/folders/xy/7y8smdfj46z_jw6lyn6wc7680000gn/T/yarn--1598891173631-0.17456750312657343/node
    Yarn: 1.17.3 - /var/folders/xy/7y8smdfj46z_jw6lyn6wc7680000gn/T/yarn--1598891173631-0.17456750312657343/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 84.0.4147.135
    Firefox: 79.0
    Safari: 13.1
  npmPackages:
    gatsby: ^2.24.14 => 2.24.14
    gatsby-image: ^2.4.13 => 2.4.14
    gatsby-plugin-graphql-image: ^1.0.1 => 1.0.1
    gatsby-plugin-intl: ^0.3.3 => 0.3.3
    gatsby-plugin-jss-provider: ^1.0.10 => 1.0.10
    gatsby-plugin-manifest: ^2.2.42 => 2.4.21
    gatsby-plugin-polyfill-io: ^1.1.0 => 1.1.0
    gatsby-plugin-react-helmet: ^3.2.1 => 3.3.10
    gatsby-plugin-react-redux: ^1.0.10 => 1.0.10
    gatsby-plugin-remote-images: ^2.1.0 => 2.2.0
    gatsby-plugin-remove-serviceworker: ^1.0.0 => 1.0.0
    gatsby-plugin-robots-txt: ^1.5.0 => 1.5.1
    gatsby-plugin-sharp: ^2.4.5 => 2.6.23
    gatsby-plugin-sitemap: ^2.2.27 => 2.4.11
    gatsby-plugin-styled-components: ^3.1.19 => 3.3.10
    gatsby-plugin-typegen: ^2.2.1 => 2.2.1
    gatsby-plugin-use-query-params: ^1.0.1 => 1.0.1
    gatsby-plugin-webpack-bundle-analyzer: ^1.0.5 => 1.0.5
    gatsby-source-apiserver: ^2.1.4 => 2.1.7
    gatsby-source-custom-api: ^2.1.4 => 2.1.4
    gatsby-source-filesystem: ^2.1.48 => 2.3.23
    gatsby-source-graphql: ^2.7.0 => 2.7.0
    gatsby-transformer-sharp: ^2.3.14 => 2.5.11
wardpeet commented 4 years ago

@pascaloliv does this still occur in the latest gatsby version?

mlenser commented 4 years ago

@wardpeet I can confirm that this occurs on the latest gatsby (2.24.53). The issue occurs on Mac, but not on windows. I get it immediately after the dev server starts (and the error kills the server).

My colleagues on Mac experience the same issue.

wardpeet commented 4 years ago

Can I get a reproduction? I can't seem to reproduce it locally on my mac.

jeffreymeng commented 4 years ago

I'm experiencing the same issue. Perhaps you can try reproducing the issue by cloning my repo? Clone https://github.com/jeffreymeng/montavistamun Run yarn install and then gatsby develop. It should fail with the error. However, if you run gatsby develop again, the error is gone.

(see #26859 for more details)

wardpeet commented 4 years ago

@jeffreymeng Thanks! I could reproduce it, will have a fix tomorrow!

lorisdev commented 4 years ago

Thanks for your effort guys ! I was too busy to come back with a reproduction recently. I'm glad your were able to have one. Can't wait to know where the bug came from. Have a great day all.

wardpeet commented 4 years ago

So the issue is that gatsby-plugin-typegen writes files into the src director during query running.

While we have calculated which queries to run after staticQueries we get back into extractingQuery state and calculateDirtyQueries will not give us the correct information anymore so it looks like we have 0 pageQueries to run

Gatsby develop log ``` $ yarn develop --verbose yarn run v1.22.4 warning ..\package.json: No license field $ gatsby develop -H 0.0.0.0 --verbose verbose set gatsby_log_level: "verbose" verbose set gatsby_executing_command: "develop" verbose loading local command from: verbose running command: develop verbose Transition to "initializing" success open and validate gatsby-configs - 0.550s success load plugins - 1.526s success onPreInit - 0.030s success initialize cache - 0.006s success copy gatsby files - 0.060s verbose [typegen] Successfully validate your configuration. { "language": "typescript", "namespace": "GatsbyTypes", "outputPath": "src/__generated__/gatsby-types.d.ts", "includeResolvers": false, "autoFix": true, "emitSchema": {}, "emitPluginDocuments": {}, "scalars": {} } verbose [typegen] Listen on query extraction success onPreBootstrap - 0.027s verbose Transition to "initializingData" success createSchemaCustomization - 0.014s verbose Transition to "initializingData" > "sourcingNodes" warn Unable to fetch firebase data for awards due to error code undefined. Using dummy data instead. verbose Now have 99 nodes with 8 types: [SitePage:1, SitePlugin:35, Site:1, SiteBuildMetadata:1, Directory:5, verbose Checking for deleted pages verbose Deleted 0 pages verbose Found 0 changed pages success Checking for changed pages - 0.007s success source and transform nodes - 0.213s verbose Transition to "initializingData" > "buildingSchema" warn Deprecation warning - adding inferred resolver for field ConferenceAwardsData.time. In Gatsby v3, only fields success building schema - 0.353s verbose Transition to "initializingData" > "creatingPages" verbose Now have 99 nodes with 8 types, and 1 SitePage nodes success createPages - 0.006s verbose Checking for deleted pages verbose Deleted 0 pages verbose Found 0 changed pages success Checking for changed pages - 0.003s verbose Transition to "initializingData" > "creatingPagesStatefully" success createPagesStatefully - 0.209s verbose Transition to "initializingData" > "rebuildingSchemaWithSitePage" success update schema - 0.017s verbose Transition to "initializingData" > "writingOutRedirects" success write out redirect data - 0.004s verbose Transition to "initializingData" > "done" verbose Transition to "runningPostBootstrap" success Build manifest and related icons - 0.142s verbose [typegen] End-up listening on query extraction. verbose [typegen] Watching schema/query changes and re-run workers verbose [typegen] Generate type definitions to src/__generated__/gatsby-types.d.ts. (language: TypeScript) success onPostBootstrap - 0.275s info bootstrap finished - 5.942s verbose Transition to "runningQueries" success onPreExtractQueries - 0.003s success extract queries from components - 0.428s verbose Transition to "runningQueries" > "writingRequires" success write out requires - 0.055s calculate [ '/dev-404-page/', '/404/', '/awards/', '/calendar/', '/conferences/', '/dashboard/', '/home-old/', '/', '/kennedy/', '/resources/', '/secretariat/', '/account/create/', '/account/', '/account/login/', '/account/logout/', '/account/recover/', '/account/send-email-verification/', '/account/settings/', '/admin/awards/', '/admin/edit-member-dashboard/', '/admin/', '/admin/members/', '/admin/synchronize-claims/', '/account/email-action/confirm-email-change/', '/account/email-action/handle/', '/account/email-action/recover-email/', '/account/email-action/reset-password/', '/account/email-action/verify-email/', '/conferences/bmun/register/', '/404.html', 'sq--src-components-index-hero-tsx', 'sq--src-components-index-about-tsx', 'sq--src-components-index-hero-video-tsx', 'sq--src-components-layout-auth-layout-tsx', 'sq--src-components-layout-navbar-tsx', 'sq--src-components-layout-seo-tsx', 'sq--src-pages-awards-tsx' ] { page: [ '/dev-404-page/', '/404/', '/awards/', '/calendar/', '/conferences/', '/dashboard/', '/home-old/', '/', '/kennedy/', '/resources/', '/secretariat/', '/account/create/', '/account/', '/account/login/', '/account/logout/', '/account/recover/', '/account/send-email-verification/', '/account/settings/', '/admin/awards/', '/admin/edit-member-dashboard/', '/admin/', '/admin/members/', '/admin/synchronize-claims/', '/account/email-action/confirm-email-change/', '/account/email-action/handle/', '/account/email-action/recover-email/', '/account/email-action/reset-password/', '/account/email-action/verify-email/', '/conferences/bmun/register/', '/404.html' ], static: [ 'sq--src-components-index-hero-tsx', 'sq--src-components-index-about-tsx', 'sq--src-components-index-hero-video-tsx', 'sq--src-components-layout-auth-layout-tsx', 'sq--src-components-layout-navbar-tsx', 'sq--src-components-layout-seo-tsx', 'sq--src-pages-awards-tsx' ] } verbose Transition to "runningQueries" > "calculatingDirtyQueries" runStaticQueries [ 'sq--src-components-index-hero-tsx', 'sq--src-components-index-about-tsx', 'sq--src-components-index-hero-video-tsx', 'sq--src-components-layout-auth-layout-tsx', 'sq--src-components-layout-navbar-tsx', 'sq--src-components-layout-seo-tsx', 'sq--src-pages-awards-tsx' ] verbose Transition to "runningQueries" > "runningStaticQueries" verbose [typegen] Generate type definitions to src/__generated__/gatsby-types.d.ts. (language: TypeScript) verbose Transition to "runningQueries" > "extractingQueries" success onPreExtractQueries - 0.009s success onPreExtractQueries - 0.005s success extract queries from components - 0.064s verbose Transition to "runningQueries" > "writingRequires" success write out requires - 0.008s calculate [] {} verbose Transition to "runningQueries" > "calculatingDirtyQueries" verbose Transition to "runningQueries" > "runningStaticQueries" runPageQueries [] 0 verbose Transition to "runningQueries" > "runningPageQueries" verbose Transition to "runningQueries" > "waitingForJobs" success run static queries - 0.826s - 7/7 8.48/s verbose [typegen] Generate type definitions to src/__generated__/gatsby-types.d.ts. (language: TypeScript) verbose Transition to "runningQueries" > "extractingQueries" success onPreExtractQueries - 0.007s success onPreExtractQueries - 0.005s success extract queries from components - 0.062s verbose Transition to "runningQueries" > "writingRequires" success write out requires - 0.005s calculate [] {} verbose Transition to "runningQueries" > "calculatingDirtyQueries" verbose Transition to "runningQueries" > "runningStaticQueries" runPageQueries [] 0 verbose Transition to "runningQueries" > "runningPageQueries" verbose Transition to "runningQueries" > "waitingForJobs" verbose Transition to "runningQueries" > "done" verbose Transition to "startingDevServers" success Generating image thumbnails - 11.374s - 53/53 4.66/s warn ⠀ warn risk - There are upcoming breaking changes: removeDeprecatedGapUtilities, purgeLayersByDefault warn risk - We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future. warn risk - https://tailwindcss.com/docs/upcoming-changes ⠀ You can now view montavistamun in the browser. ⠀ Local: http://localhost:8000/ On Your Network: http://10.8.0.1:8000/ ⠀ View GraphiQL, an in-browser IDE, to explore your site's data and schema ⠀ Local: http://localhost:8000/___graphql On Your Network: http://10.8.0.1:8000/___graphql ⠀ Note that the development build is not optimized. To create a production build, use gatsby build ⠀ warn ESLintError: C:\Users\Ward\projects\gatsby\tmp\montavistamun\gatsby-browser.js 12:32 warning Missing return type on function @typescript-eslint/explicit-module-boundary-types 12:33 warning Object pattern argument should be typed @typescript-eslint/explicit-module-boundary-types ✖ 2 problems (0 errors, 2 warnings) success Building development bundle - 20.830s verbose Transition to "waiting" ERROR ENOENT: no such file or directory, open 'C:\Users\Ward\projects\gatsby\tmp\montavistamun\.cache\json\_dev-404-page_.json' Error: ENOENT: no such file or directory, open 'C:\Users\Ward\projects\gatsby\tmp\montavistamun\.cache\json\_dev- 404-page_.json' error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. ```
wardpeet commented 4 years ago

Successfully published: