sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.7k stars 111 forks source link

Failed to load static file for page: /qa/opportunities ENOENT: no such file or directory, open '/var/task/.next/server/pages/qa/opportunities.html' #366

Closed mfrangakis closed 3 months ago

mfrangakis commented 4 months ago

Attempting to directly access some paths returns a 500 Internal Server Error, with the error Failed to load static file for page: /qa/opportunities ENOENT: no such file or directory, open '/var/task/.next/server/pages/qa/opportunities.html'

The example above would normally be accessible at /qa/opportunities, and it is accessible without issue in my development environment (localhost:3000/qa/opportunities).

Notably, this issue only occurs on the deployed stage if one types the URL into the browser (or refreshes the page). If you navigate from a <Link /> component provided by Next.js, then the issue does not occur and the page can be accessed.

Looking at the output of the open-next command, the open-next\server\.next folder is missing the html files for most of the routes: image

The above folders are empty as you can see; when in reality, there are quite a few routes in them. To illustrate, compared this to the output of just running the standard Next build command; the .next folder has all the html files I expected (including opportunities): image

Note that the open-next cache does appear to have the right files too: image

Other routes are redacted above for confidentiality reasons.

Environment Next.js 14.1.0 OpenNext 2.3.6 Deployed via SST to the AWS af-south-1 region

mfrangakis commented 4 months ago

Looking through the open-next codebase, I can see that these html files are removed purposely as they are static, and are to be served by the cache. They are indeed cached, as from the 3rd screenshot in the original post. Is this an issue with SST then, that the cache is not being properly served?

conico974 commented 4 months ago

Are you using getStaticProps for this route ? ISR ? Are you building on windows ?

mfrangakis commented 4 months ago

Nope, not using either getStaticProps, ISR or getServerSideProps. I use client-side fetching with SWR. Note that this same issue occurs on all the other "cached" routes as well. Sorry, forgot to mention the build environment - Windows 11 22H2.

khuezy commented 4 months ago

I have a feeling this is a windows path issue (nextjs bug.) Can you try building in WSL?

conico974 commented 4 months ago

It's definitely an issue with windows. There is several issues here (next has some issue with windows path, and i'm pretty sure the open-next plugins does not apply properly on windows as well) If the plugin don't work it explains why it tries to load the file using the filesystem cache handler instead our own.

mfrangakis commented 4 months ago

Sorry for the delay - needed to install and configure WSL with node, AWS credentials, etc.

Building and deploying in WSL resulted in routes that now work as expected: /qa/opportunities does not return a 500 Internal server error but loads properly. Thanks for the help!

Where does this leave us with the Windows path handling issue? Is it something that could be looked at? Building in WSL is not a problem (albeit a lot slower), but given that my environment is Windows, it would be more convenient to have that option.

conico974 commented 4 months ago

At the moment i don't think we should put too much effort into windows support for a couple of reasons:

Personally i won't work on windows support (i don't have a good windows machine), but maybe in the future someone will be willing to work on this

conico974 commented 3 months ago

I'll close all the windows related issue in favor of https://github.com/sst/open-next/issues/385