avitorio / outstatic

Outstatic - A static CMS for Next.js
https://Outstatic.com
Other
2.73k stars 161 forks source link

NextJS Prefetch triggers ENOENT Error with solution #245

Closed salincakli closed 3 weeks ago

salincakli commented 3 months ago

Provide environment information

next: 15.0.0-rc.0 outstatic: 1.4.9 react: 19.0.0-rc

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

vercel

Describe the Bug

this error occured right after adding a new api route:

Workaround

As I suspected a prefetch I wrote a check for prefetch in the new function:

  const isPrefetch = url.searchParams.get('prefetch') === 'true';

returning this json {message: "Prefetch request"} interrupts this request. I suppose that alternatively router option can be set.

Another User with this error wrote into the vercel help discussion forum:

https://github.com/orgs/vercel/discussions/6918

Expected Behavior

`
Error in Function: /[...slug]
[Error: ENOENT: no such file or directory, open '/var/task/outstatic/content/metadata.json'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/task/outstatic/content/metadata.json',
  digest: '2192603207'
}`

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://outstatic-web.vercel.app/docs/getting-started#deploy-with-vercel

To Reproduce

create nextjs /api/customFunction route.tsx

trying to render /[...slug] fails

avitorio commented 3 weeks ago

Hi @salincakli,

I'd need more information here. Can you try adding export const dynamic = 'force-static' to your page?