Hi! I’m trying to get an SSR page on Gatsby working. It works locally with netlify dev, but not when deployed. The function crashes with
Error - ENOENT: no such file or directory, lstat '/var/task/.cache/data'
Error: ENOENT: no such file or directory, lstat '/var/task/.cache/data'
at Object.lstatSync (node:fs:1668:3)
at Object.lstatSync (/var/task/node_modules/graceful-fs/polyfills.js:318:34)
at statFunc (/var/task/node_modules/fs-extra/lib/util/stat.js:24:20)
at getStatsSync (/var/task/node_modules/fs-extra/lib/util/stat.js:25:19)
at Object.checkPathsSync (/var/task/node_modules/fs-extra/lib/util/stat.js:67:33)
at Object.copySync (/var/task/node_modules/fs-extra/lib/copy/copy-sync.js:27:38)
at setupFsWrapper (/var/task/hem-store-us/.cache/page-ssr/lambda.js:64:10)
at Object.<anonymous> (/var/task/hem-store-us/.cache/page-ssr/lambda.js:70:16)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
Could it be related to the SSR page is inside a gatsby theme I reuse for multiple pages?
My structure
/
- my-site/ (the site that Netlify builds, and this site uses my-theme in my yarn monorepo)
- my-theme/
src/
pages/
orders/
[orderId].tsx (this is the page that wants to use SSR)
I’d guess that you are trying to somehow write or read local files in the lambda which in general isn’t a typical use pattern as far as I know. Since we mock the lambda in netlify dev it’s not entirely unexpected that it would work differently locally than in the cloud.
I wonder if you could update your code to use /tmp for this file/directory, instead of /var/<anything> as that appears to be a better-suited location for writing things to the “local filesystem” in a lambda. I’m not a lambda user myself so please take this with a grain of salt, as I am only attempting to address the proximate symptom you’ve shown.
Unfortunately, Gatsby itself uses those paths under-the-hood. This was discovered when investigating another issue (which is highly similar to this), but sadly that’s not fixed yet, so very likely this issue would also just remain at the moment.