gatsby: Building static HTML for pageserror: Error: ENOENT: no such file or directory

Description

I’m getting a lot of similar errors to this:

 success Building production JavaScript and CSS bundles — 8.258 s
 ⠐ Building static HTML for pageserror ../public/29/path---internal-80-aeac-04-012-a-4-feb-9-d-99-d- 
   6053-a-12-be-5-a-r-006-91-c-794-olfyUiQvtLIAh9ozYkUiFQEB1M
 { Error: ENOENT: no such file or directory, open' X:\xxx\xxx\public\static\d\29\path---internal-80-aeac-04-012-a-4-feb-9-d-99-d-6053-a-12-be-5-a-r-006-91-c-794-olfyUiQvtLIAh9ozYkUiFQEB1M.json'

and then hangs with " Building static HTML for pages" for long time.

Steps to reproduce

Don’t know… Just deleted the public folder and build it.

Environment

Run gatsby info --clipboard in your project directory and paste the output here. Not working? You may need to update your global gatsby-cli - npm install -g gatsby-cli

System: OS: Windows 10 CPU: x64 Intel® Core™ i7-5600U CPU @ 2.60GHz Binaries: Yarn: 1.9.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 5.5.1 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 42.17134.1.0 npmPackages: gatsby: ^2.0.67 => 2.0.67 gatsby-image: ^2.0.25 => 2.0.25 gatsby-plugin-catch-links: ^2.0.9 => 2.0.9 gatsby-plugin-emotion: ^3.0.1 => 3.0.1 gatsby-plugin-google-analytics: ^2.0.8 => 2.0.8 gatsby-plugin-manifest: ^2.0.12 => 2.0.12 gatsby-plugin-offline: ^2.0.19 => 2.0.19 gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0 gatsby-plugin-sharp: ^2.0.15 => 2.0.15 gatsby-plugin-sitemap: ^2.0.3 => 2.0.3 gatsby-plugin-typescript: ^2.0.3 => 2.0.3 gatsby-plugin-typography: ^2.2.2 => 2.2.2 gatsby-remark-component: ^1.1.3 => 1.1.3 gatsby-remark-images: ^3.0.1 => 3.0.1 gatsby-source-filesystem: ^2.0.12 => 2.0.12 gatsby-transformer-remark: ^2.1.15 => 2.1.15 gatsby-transformer-sharp: ^2.1.9 => 2.1.9

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 47 (12 by maintainers)

Most upvoted comments

I deleted my public folder and build again, same error again.

I deleted cache folder and build and now it worked.

I just ran into this as well.

For future people: the tl; dr is that when making a fresh build, delete both public and .cache.

If I run gatsby start and then run gatsby build it fails. If I delete the cache folder and run gatsby build it works.

Not sure if it’s related but I found this issue ^ while googling a solution…

I am running npm run serve after gatsby clean however I get this error when trying to view localhost:9000.

Error: ENOENT: no such file or directory, stat '/xxx/xxx/gatsby-site/public/404.html'

Not sure if it’s related but I found this issue ^ while googling a solution…

I am running npm run serve after gatsby clean however I get this error when trying to view localhost:9000.

Error: ENOENT: no such file or directory, stat '/xxx/xxx/gatsby-site/public/404.html'

Same here

We do output query results to public directory directly, but we keep track of them in .cache - so if you delete public without deleting .cache - cache won’t know that query results are no longer there and that’s why we it complains about missing file that cache expects to be there

I was having CI build issues. I was caching /.cache/ but not ./public/ and that caused this error to happen. Keeping both or deleting both will fix this issue as it is appear. I have a small worry though.

I see alot of people here talking about “always cleaning both” but that is definitely a no-go as build time is a critical factor.

So my only option is to keep both, but I fear that will lead to remnants of old builds being deployed with new statics.

The design decision of keeping cached stuff in the build output folder is a weird one. File copy time and disk space is insignificant to most people compared to query speed.

At the very least the error message in this code path should be changed to something like “./.cache was expecting file /page-data.json to be present in public/ folder. If this was deleted, please delete both .cache/ and public/ or run gatsby clean to avoid this issue”

Also side note: You can also use gatsby clean which will delete both for you. Released in gatsby-cli@2.4.11

We can maybe add a gatsby clean to the cli that deletes both the folders but generally, @jonniebigodes makes a good point that these folders ought not to be touched since they are owned by gatsby .

Apologies for the not very helpful error messages. We are working towards improving this.

After executing npm run build gatsby serve started to working properly. What I did:

  1. npm install - warnings
  2. gatsby serve - error
  3. delete public and .cache
  4. gatsby serve - error
  5. gatsby develop - ok
  6. npm run build - ok
  7. gatsby serve - ok

@sidharthachatterjee Ok, cool. Thanks.

@pieh I’m not sure how would that work when you build for dev vs build for prod. Looks like the prod build uses dev assets. I don’t feel very safe about it, but looks like has no problems for now.

@jonniebigodes I think the code should do its best to avoid developer mistakes. For example rememering to delete .cache before you build is an antipattern. Why not delete the .cache folder when you run the build automatically? You will do one mistake at one point.

I am having a similar issue using Firebase 6.5.0, WebpackError: ReferenceError: IDBIndex is not defined.

When i change the firebase version to 5.9.0 the build works fine without issues. Anyone solved this when using firebase?

We have encountered this issue on a CICD environment where we cache /public and /.cache in order to speed up builds…

If we eliminate the cache then builds will be slow again… 😢

Well, maybe you have to log in for that community. Here the long story short:

  • for a large update I had to synchronize SQL-changes and app deployment
  • I built the app, applied the sql changes then deployed on zeit/now as hundreds of times before
  • unfortunately the deployment hit a 10’000 file limit
  • my app was broken, it was 23.00 at night after a hard days work and I had to get things working again
  • I thought: maybe the public folder contains unneeded stuff. Emptied it. Tried to build and hit the errors mentioned in this issue
  • I found this issue, deleted public folder and .cache folder, rebuilt - and found only 600 files in the public folder

Minus 9’400 files!

After this deployment worked again 😃

my app was broken, it was 23.00 at night after a hard days work

Reading this after writing it makes me realize just how bad I had timed this 😐

Ok, so I had this issue: https://github.com/gatsbyjs/gatsby/issues/10458 I run gatsby develop a few times and now it works. Then I build and it works… what is going on? I need to run gatsby develop before building?