Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ENOENT: no such file or directory" - next.js crashes, related to image caching? #33860

Closed
bonesoul opened this issue Feb 1, 2022 · 31 comments · Fixed by #33883 or #34210
Closed

"ENOENT: no such file or directory" - next.js crashes, related to image caching? #33860

bonesoul opened this issue Feb 1, 2022 · 31 comments · Fixed by #33883 or #34210
Assignees
Labels
Image (next/image) Related to Next.js Image Optimization.

Comments

@bonesoul
Copy link

bonesoul commented Feb 1, 2022

Run next info (available from version 12.0.8 and up)

root@1d90163fc150:/app# npx --no-install next info
/bin/sh: 1: pnpm: not found

    Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Debian 4.19.171-2 (2021-01-30)
    Binaries:
      Node: 17.4.0
      npm: 8.3.1
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.0.10
      react: 17.0.2
      react-dom: 17.0.2

What version of Next.js are you using?

12.0.10

What version of Node.js are you using?

17.4.0

What browser are you using?

Chrome

What operating system are you using?

Debian

How are you deploying your application?

next build

Describe the Bug

Upgraded my site to next.js 12.0.10 and with the new release started getting errors;

today at 2:27:38 PMready - started server on 0.0.0.0:3000, url: http://localhost:3000
today at 2:27:38 PMinfo  - Loaded env from /app/.env.production
today at 2:27:38 PMinfo  - Loaded env from /app/.env
today at 2:27:39 PMwarn  - SWC minify beta enabled. https://nextjs.org/docs/messages/swc-minify-enabled
today at 2:37:32 PMError: ENOENT: no such file or directory, open '/app/.next/cache/images/iLU6LIXA6TCl8SepFjJ5LNbyzLiOqZ7U49T1Ftm+jW4=/0.1643714865404.blKDVxGlp5+pf7TBeZBnD7i-BF2A5hQCHH0jGL--cVU=.avif'

and then next server dies and restarts

Expected Behavior

shouldn't be crashing.

To Reproduce

any code with avif + image caching support i guess

@bonesoul bonesoul added the bug Issue was opened via the bug report template. label Feb 1, 2022
@bonesoul bonesoul changed the title next.js crashing - related to image caches? "ENOENT: no such file or directory" - next.js crashes, related to image caching? Feb 1, 2022
@bonesoul
Copy link
Author

bonesoul commented Feb 1, 2022

disabled avif but now also getting the same issue with webp images:

ENOENT: no such file or directory, open '/app/.next/cache/images/zI1zuWH5IH-N5N0jSgcuQfhtq3QexsW6tQsi7zjMKSs=/0.1643720036128.wPZdv3V4PWqtqo2xcqzGTEnd03SEeji615bPHom1Z-0=.webp'

@bonesoul
Copy link
Author

bonesoul commented Feb 1, 2022

downgraded to 12.0.9 now and it seems all good, i think this may be the offfending commit: #33719

@andersonba
Copy link

andersonba commented Feb 1, 2022

Same here

    Operating System:
      Platform: linux
      Arch: x64
      Version: #107~16.04.1-Ubuntu SMP Fri Feb 26 16:08:47 UTC 2021
    Binaries:
      Node: 16.13.0
      npm: 8.1.0
      Yarn: 1.22.10
      pnpm: N/A
    Relevant packages:
      next: 12.0.10
      react: 17.0.2
      react-dom: 17.0.2
Error: ENOENT: no such file or directory, open '/app/.next/cache/images/HzZlZ8LwX5yhyrTFeQMYEB4hhx97JC+MY7cUDEPrASw=/3600.1643726214517.ma-zVhFpWc8J-pqc-BfyUnRCC8OW4anHCDBD9q8N+I4=.webp'
Error: ENOENT: no such file or directory, open '/app/.next/cache/images/HzZlZ8LwX5yhyrTFeQMYEB4hhx97JC+MY7cUDEPrASw=/3600.1643726214517.ma-zVhFpWc8J-pqc-BfyUnRCC8OW4anHCDBD9q8N+I4=.webp'

[edited]

Apparently, it worked again in version 12.0.9

@icflorescu
Copy link

Same here. I can also confirm it happens on Node.js 16.13.2 LTS. It's actually pretty bad - my production app started failing and the Docker container kept restarting once every few requests.

It does work after reverting to 12.0.9.

@styfle styfle added Image (next/image) Related to Next.js Image Optimization. kind: bug and removed bug Issue was opened via the bug report template. labels Feb 1, 2022
@styfle styfle self-assigned this Feb 1, 2022
@quocthangit247

This comment has been minimized.

@styfle
Copy link
Member

styfle commented Feb 2, 2022

I'm not able to reproduce, but I believe there's a race condition when the stale image is being served from the cache but it gets deleted before the stream completes.

PR #33883 should fix it.

If anyone could provide a repo that crashes every time, that would be great to validate so we could add it as an integration test to avoid regressing.

@b-novikov-ipersonality
Copy link

@styfle hey. Here's the repo that crashes: https://github.com/b-novikov-ipersonality/nextjs-cache-crash

  1. yarn build
  2. yarn start
  3. Open http://localhost:3000
  4. Refresh page
  5. Experience crash.

@styfle
Copy link
Member

styfle commented Feb 2, 2022

Great, thanks!

I was able to reproduce once adding a Dockerfile and a few other steps mentioned in this PR.

@styfle
Copy link
Member

styfle commented Feb 2, 2022

This is fixed on canary, thanks!

You can try it out today with npm i next@canary or yarn add next@canary.

I also discovered that serving stale images wasn't any faster because revalidation wasn't happening in the background, it was blocking. So I created PR #33930 with the another fix. (Update: closed in favor of #34075)

Update: This has been released in Next.js 12.1.0

@danielGz
Copy link

danielGz commented Feb 5, 2022

I downgraded to 12.0.9 and also installed the canary version and although the server doesn't crash I get the error a lot and reloading the page has unpredictable behavior with images, sometimes few of them load sometimes others won't.

@ghost
Copy link

ghost commented Feb 6, 2022

Wow thanks. This is one of those rare occasions that I search for an error, only to find it wasn't my mistake and fixed in the last few days 😍

Sending appreciation for next@canary and nextjs team!

@yayza
Copy link

yayza commented Feb 10, 2022

Downgraded to 12.0.9 fixed it for me (no errors or crash), the new canary version would still throw errors every time I scrolled past an image, but wouldn't crash server like 12.0.10.

@ijjk
Copy link
Member

ijjk commented Feb 10, 2022

@yayza have you tried v12.0.11-canary.11 this has been updated some more in that version and should be resolved now.

@gngo2018
Copy link

Ran into this issue when trying to install. Has anyone else come across this?

npm ERR! Found: [email protected]
npm ERR! node_modules/next
npm ERR! next@"^12.0.11-canary.11" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer next@">=10.2.0" from [email protected]
npm ERR! node_modules/eslint-config-next
npm ERR! dev eslint-config-next@"11.0.1" from the root project

@ijjk
Copy link
Member

ijjk commented Feb 10, 2022

@gngo2018 it looks like you have other dependencies that need to be updated as well e.g. eslint-config-next

@yayza
Copy link

yayza commented Feb 10, 2022

@yayza have you tried v12.0.11-canary.11 this has been updated some more in that version and should be resolved now.

@ijjk Yes, I also tried v12.0.11-canary.12 and it works as far as the server doesn't crash, but I still get these types of errors filling up server console for every image I scroll past when viewing the site:

[Error: ENOENT: no such file or directory, stat 'C:\Users\yaeza\Desktop\Projects\as\.next\cache\images\5RqXPEoGLuXkIjTm2UDMsDVWjM4mCsyLvUfP3suox88='] {
  errno: -4058,
  syscall: 'stat',
  path: 'C:\\Users\\yaeza\\Desktop\\Projects\\as\\.next\\cache\\images\\5RqXPEoGLuXkIjTm2UDMsDVWjM4mCsyLvUfP3suox88='
}

@ijjk
Copy link
Member

ijjk commented Feb 11, 2022

@yayza can you confirm you updated properly with yarn why next or npm ls next? The reading of the cache is now wrapped in a try/catch so the error should not be able to be logged anymore x-ref

const buffer = await promises.readFile(join(cacheDir, file))

@yayza
Copy link

yayza commented Feb 11, 2022

@yayza can you confirm you updated properly with yarn why next or npm ls next? The reading of the cache is now wrapped in a try/catch so the error should not be able to be logged anymore x-ref

const buffer = await promises.readFile(join(cacheDir, file))

@ijjk I just checked and it says it's the updated version

https://streamable.com/5l59q7

@ijjk
Copy link
Member

ijjk commented Feb 11, 2022

@yayza Ah I see, thanks for sharing that additional info, looks like this is an issue with writing to cache specifically with the rmdir method used to clean the dir. I opened a PR with a fix for this here #34210

kodiakhq bot pushed a commit that referenced this issue Feb 11, 2022
This ensures we handle `EEXISTS` with `fs.rmdir` for Node.js `v12` and use `fs.rm` when available instead as it is the replacement for `fs.rmdir` with the `recursive` option. 

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: #33860 (comment)
@shyamsukhamit
Copy link

Facing the same issue event after updating to nextjs 12.0.9 - docker is crashing every now and then - in my live app. This is my first app. Can anyone please help!

@havran
Copy link

havran commented Feb 11, 2022

Facing the same issue event after updating to nextjs 12.0.9 - docker is crashing every now and then - in my live app. This is my first app. Can anyone please help!

You should lock NextJS to version 12.0.9:

    "next": "12.0.9", // !!! without ^ before
    // and from devDependencies
    "@next/bundle-analyzer": "12.0.9",
    "eslint-config-next": "12.0.9",

and npm install again.

@shyamsukhamit
Copy link

Facing the same issue event after updating to nextjs 12.0.9 - docker is crashing every now and then - in my live app. This is my first app. Can anyone please help!

You should lock NextJS to version 12.0.9:

    "next": "12.0.9", // !!! without ^ before
    // and from devDependencies
    "@next/bundle-analyzer": "12.0.9",
    "eslint-config-next": "12.0.9",

and npm install again.

Thanks @havran it seems to be working now - still monitoring.

@ijjk
Copy link
Member

ijjk commented Feb 11, 2022

@yayza the above PR is now landed in v12.0.11-canary.13, please update and give it a try!

@yayza
Copy link

yayza commented Feb 11, 2022

No more errors, thanks alot for the quick fix!

@joggienl
Copy link

I have this error as well, @ijjk out of curiosity, when is 12.0.11 planned to be released? Knowing would help me in how I would like to work around this for now.

@tm1000
Copy link
Contributor

tm1000 commented Feb 17, 2022

@joggienl they just released 12.1.0 today

@joggienl
Copy link

so the answer to when is never 😅

@derkoe
Copy link

derkoe commented Feb 18, 2022

Is the fix in 12.1?

Just found it - it is in 12.1: e3e62aa

@joggienl
Copy link

@derkoe you can check the release information here: https://github.com/vercel/next.js/releases/tag/v12.1.0

There is a reference to the pull requests that are mentioned in this issue:

#33883
#34075
#34210

bertyhell added a commit to viaacode/hetarchief-client that referenced this issue Feb 22, 2022
2022-02-22T10:28:12.259	client-tst	Error: ENOENT:
no such file or directory,
open '/app/.next/cache/images/jyLfZatL4kb....bk5QE=/0.1645521961763.w6...1XPU=.webp'
	client	hetarchief

vercel/next.js#33860 (comment)
@MobinX
Copy link

MobinX commented Feb 26, 2022

oh it seems to be fixed
yarn add next@latest
yarn build && yarn start

no more crashing

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Image (next/image) Related to Next.js Image Optimization.
Projects
None yet