gatsbyjs / gatsby

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

Build cache is dependent on outputs, later builds crash if public folder deleted #17981

Closed Silic0nS0ldier closed 5 years ago

Silic0nS0ldier commented 5 years ago

Description

When running gatsby build after having removed public from an earlier build, the build fails to due an attempted read of public folder contents.

Steps to reproduce

  1. Run gatsby build
  2. Delete ./public folder
  3. Run gatsby build
  4. Observe build fail with output similar to
~\Desktop\source\Blog [master ≡]> .\node_modules\.bin\gatsby build
success open and validate gatsby-configs - 0.091 s
success load plugins - 1.638 s
success onPreInit - 0.050 s
success delete html and css files from previous builds - 0.060 s
success initialize cache - 0.056 s
success copy gatsby files - 0.288 s
warn gatsby-plugin-feed was initialized in gatsby-config.js without a feeds option.
This means that the plugin will use the internal RSS feed creation, which may not match your use case.
This behavior will be removed in the next major release of gatsby-plugin-feed.
For more info, check out: https://gatsby.dev/adding-rss-feed
success onPreBootstrap - 0.088 s
success source and transform nodes - 0.299 s
success Add explicit types - 0.060 s
success Add inferred types - 0.268 s
success Processing types - 0.252 s
success building schema - 0.988 s
success createPages - 0.639 s
success createPagesStatefully - 0.356 s
success onPreExtractQueries - 0.079 s
success update schema - 0.158 s
success extract queries from components - 0.816 s
success write out requires - 0.072 s
success write out redirect data - 0.056 s
success onPostBootstrap - 0.065 s
⠀
info bootstrap finished - 10.062 s
⠀
success run static queries - 0.118 s — 3/3 80.11 queries/second
success Building production JavaScript and CSS bundles - 6.825 s
success run page queries - 0.079 s — 1/1 215.16 queries/second
success Generating image thumbnails — 20/20 - 13.657 s

 ERROR #95313 

Building static HTML failed for path "/docker-commands/"

See our docs page for more info on this error: https://gatsby.dev/debug-html

  Error: ENOENT: no such file or directory, open 'C:\Users\REDACTED\Desktop\source\Blog\public\page-data\docker-commands\page-data.json'

  - render-page.js:563 Module../.cache/static-entry.js.__webpack_exports__.default
    C:/Users/REDACTED/Desktop/source/Blog/public/render-page.js:563:1490

  - render-html.js:35 
    [Blog]/[gatsby]/dist/utils/worker/render-html.js:35:36

  - debuggability.js:313 Promise._execute
    [Blog]/[bluebird]/js/release/debuggability.js:313:9

  - promise.js:488 Promise._resolveFromExecutor
    [Blog]/[bluebird]/js/release/promise.js:488:18

  - promise.js:79 new Promise
    [Blog]/[bluebird]/js/release/promise.js:79:10

  - render-html.js:31 
    [Blog]/[gatsby]/dist/utils/worker/render-html.js:31:37

  - util.js:16 tryCatcher
    [Blog]/[bluebird]/js/release/util.js:16:23

  - map.js:61 MappingPromiseArray._promiseFulfilled
    [Blog]/[bluebird]/js/release/map.js:61:38

  - promise_array.js:114 MappingPromiseArray.PromiseArray._iterate
    [Blog]/[bluebird]/js/release/promise_array.js:114:31

  - promise_array.js:78 MappingPromiseArray.init
    [Blog]/[bluebird]/js/release/promise_array.js:78:10

  - map.js:30 MappingPromiseArray._asyncInit
    [Blog]/[bluebird]/js/release/map.js:30:10

  - async.js:142 _drainQueueStep
    [Blog]/[bluebird]/js/release/async.js:142:12

  - async.js:131 _drainQueue
    [Blog]/[bluebird]/js/release/async.js:131:9

  - async.js:147 Async._drainQueues
    [Blog]/[bluebird]/js/release/async.js:147:5

⠧ Building static HTML for pages

Reproduction repo: https://github.com/Silic0nS0ldier/gatsby-bug-17981

Expected result

Build passes

Actual result

Build fails

Environment

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  Binaries:
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 3.7.4
  Browsers:
    Edge: 44.18362.10022.0
  npmPackages:
    gatsby: ^2.15.28 => 2.15.28 
    gatsby-image: ^2.2.23 => 2.2.23 
    gatsby-plugin-feed: ^2.3.15 => 2.3.15 
    gatsby-plugin-preact: ^3.1.13 => 3.1.13 
    gatsby-plugin-react-helmet: ^3.1.10 => 3.1.10 
    gatsby-plugin-sharp: ^2.2.27 => 2.2.27 
    gatsby-plugin-typescript: ^2.1.11 => 2.1.11 
    gatsby-remark-abbr: ^1.0.0 => 1.0.0 
    gatsby-remark-copy-linked-files: ^2.1.23 => 2.1.23 
    gatsby-remark-images: ^3.1.25 => 3.1.25 
    gatsby-remark-smartypants: ^2.1.11 => 2.1.11 
    gatsby-remark-vscode: ^1.2.1 => 1.2.1 
    gatsby-source-filesystem: ^2.1.28 => 2.1.28 
    gatsby-transformer-remark: ^2.6.26 => 2.6.26 
    gatsby-transformer-sharp: ^2.2.19 => 2.2.19 
    gatsby-transformer-yaml: ^2.2.12 => 2.2.12 
LekoArts commented 5 years ago

Thank you for opening this!

When deleting the public folder you should also delete the .cache folder. That's what our CLI via gatsby clean does. You shouldn't have issues when using gatsby clean.

We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby!

Aditya94A commented 4 years ago

I think it'd be a good idea to display some kind of warning before gatsby starts building that checks if the .cache contents are in fact valid.