Error LogERROR AMP Optimizer ERROR Could not write cache file Error: EROFS: read-only file system, mkdir '/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/.cache' at mkdirSync (fs.js:987:3) at FileSystemCache.set (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:31718) at downloadAmpRuntimeStyles_ (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:48628) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async fetchAmpRuntimeStyles_ (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:48040) at async initRuntimeStyles (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:46388) at async fetchRuntimeParameters (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:45656) at async DomTransformer.transformTree (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:38083) at async DomTransformer.transformHtml (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:37967) at async renderToHTML (/var/task/node_modules/next/dist/next-server/server/render.js:59:218) { errno: -30, syscall: 'mkdir', code: 'EROFS', path: '/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/.cache' }
Vercel Support team response
It looks like it's an issue with the AMP optimizer module itself. They are trying to write the cache to a directory that they do not have access to. Instead, the ideal behavior will be for them to leverage the node os module and get access to the system's temporary directory like the following: os.tmpdir(). I suggest raising an issue on the official Amp Toolbox repo mentioning your error and explaining how the cache should be written to a temporary directory or at least configurable through some options.
Framework: NextJs 10.0.9, React 17.0.1 Platform: vercel.com
I have implemented getstaticprops (https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) for one of my pages with AMP. While loading the page, sometimes the page crashes due to the error "AMP Optimizer ERROR Could not write cache file Error"
Error Log
ERROR AMP Optimizer ERROR Could not write cache file Error: EROFS: read-only file system, mkdir '/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/.cache' at mkdirSync (fs.js:987:3) at FileSystemCache.set (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:31718) at downloadAmpRuntimeStyles_ (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:48628) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async fetchAmpRuntimeStyles_ (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:48040) at async initRuntimeStyles (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:46388) at async fetchRuntimeParameters (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:45656) at async DomTransformer.transformTree (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:38083) at async DomTransformer.transformHtml (/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/index.js:1:37967) at async renderToHTML (/var/task/node_modules/next/dist/next-server/server/render.js:59:218) { errno: -30, syscall: 'mkdir', code: 'EROFS', path: '/var/task/node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/.cache' }
Vercel Support team response It looks like it's an issue with the AMP optimizer module itself. They are trying to write the cache to a directory that they do not have access to. Instead, the ideal behavior will be for them to leverage the node
os
module and get access to the system's temporary directory like the following:os.tmpdir()
. I suggest raising an issue on the official Amp Toolbox repo mentioning your error and explaining how the cache should be written to a temporary directory or at least configurable through some options.