1

Hello Sitecore Community,

I would like to share a problem with Next JS app,

We are using Azure Linux Web App with Node JS 20 and Next JS version 14.2.25.

If anyone has faced similar issue or some suggestion.

⨯ Failed to write image to cache 5cv6qnjptWX6SB1NYl+U8ruPAJYmCLm3JI6f33bnmmE= Error: ENOENT: no such file or directory, mkdir '/home/site/wwwroot/.next/cache' at async Object.mkdir (node:internal/fs/promises:858:10) at async writeToCacheDir (/home/site/wwwroot/node_modules/next/dist/server/image-optimizer.js:178:5) at async ImageOptimizerCache.set (/home/site/wwwroot/node_modules/next/dist/server/image-optimizer.js:451:13) at async /home/site/wwwroot/node_modules/next/dist/server/response-cache/index.js:121:25 at async /home/site/wwwroot/node_modules/next/dist/lib/batcher.js:45:32 { errno: -2, code: 'ENOENT', syscall: 'mkdir', path: '/home/site/wwwroot/.next/cache' } 

Another Instance of the error

Failed to update prerender cache for /en/_site_xyz/abc/def Error: ENOENT: no such file or directory, mkdir '/home/site/wwwroot/.next/server/pages/en/_site_xyz/abc' at async Object.mkdir (node:internal/fs/promises:858:10) at async FileSystemCache.set (/home/site/wwwroot/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js:263:13) at async IncrementalCache.set (/home/site/wwwroot/node_modules/next/dist/server/lib/incremental-cache/index.js:400:13) at async /home/site/wwwroot/node_modules/next/dist/server/response-cache/index.js:121:25 at async /home/site/wwwroot/node_modules/next/dist/lib/batcher.js:45:32 { errno: -2, code: 'ENOENT', syscall: 'mkdir', path: '/home/site/wwwroot/.next/server/pages/en/_site_xyz/abc' } 
2
  • How are you deploying? Does the ls -la /home/site/wwwroot/.next dir exist? If not, your deploy is not copying build artifacts ornpm run build isn’t running on deploy. Commented Aug 12 at 16:08
  • Yes, the folder exists and under that cache and server folder is also there.. but all the files in there shows an outdated image or html/json file. npm run build is executed as part of the deploy package getting through build pipeline in Azure DevOps Commented Aug 13 at 5:10

2 Answers 2

3

If the .next/cache and .next/server folders exist but contain outdated files after deployment, the issue is likely related to your build and deployment process in Azure DevOps.

Here’s how to troubleshoot and resolve it:

1. Clean the .next Directory Before Building Ensure your pipeline deletes the .next folder before running npm run build to avoid using stale cache and server files.

Add this step before your build:

rm -rf .next 

2. Verify Build Artifacts After running npm run build, check that the .next directory contains up-to-date files locally before packaging and deploying.

3. Deploy Only Fresh Build Artifacts Make sure your pipeline is packaging and deploying the newly built .next folder, not a previously cached or stored version.

4. Check Azure App Service Settings

If using WEBSITE_RUN_FROM_PACKAGE=1, the file system is read-only after deployment. This means any runtime changes (like image optimization or cache updates) won’t persist.

• For dynamic image optimization, consider using Azure Blob Storage or a custom cache location.

5. Review Pipeline Steps

Ensure your Azure DevOps pipeline:

• Cleans old artifacts.

• Runs npm run build after cleaning.

• Deploys the correct output to Azure.

Hope this help!!

1
  • Thank you Parveen for the troubleshooting steps. Issue was with #4, the environment variable was making the wwwroot Read-Only, removing that solved the issue. Commented Aug 18 at 6:10
0

Since you are getting ENOENT on mkdir, it means the app is trying to create a new folder inside an existing path, but can't due to restricted write permissions in the App Service runtime environment (/home/site/wwwroot).

You can try writing cache to some other writable directory and try if it works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.