sst / open-next

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

Issue using apps directory #328

Closed ziggy6792 closed 7 months ago

ziggy6792 commented 7 months ago

Hi firstly thanks so much for this!

I had a lot of success deploying this using next 13 and the old pages directory but not the new apps directory.

When I use the new apps directory my deployed site just returns null https://dvy374fpkcsdt.cloudfront.net/ Screenshot 2023-12-04 at 1 44 17 AM Example branch here https://github.com/ziggy6792/typescript-journey/tree/apps-directory It is very hard to debug. I see no issues in the server lambda or in the browser console.

But using the old next JS pages directory everything works fine Example branch here https://github.com/ziggy6792/typescript-journey/tree/pages-directory

FYI both sample next apps above were simply created from t3 https://create.t3.gg/ just with EXPERIMENTAL Would you like to use Next.js App Router? on or off

I thought maybe apps directory is not supported yet. But it says here that it is https://open-next.js.org/

Any help would be very very much appreciated.

Thanks,

khuezy commented 7 months ago

IMO, T3 is a trap... anyways, it's b/c you're using trpc:

unstable_httpBatchStreamLink

This requires streaming to be enabled, (see NextjsSite docs)

ziggy6792 commented 7 months ago

Wow thanks for such a quick reply. I take your point about T3

So it seem you are saying I have 2 options?

  1. Remove the unstable_httpBatchStreamLink This had no effect

  2. Enable steaming https://docs.sst.dev/constructs/NextjsSite as shown here I got a different issue Screenshot 2023-12-04 at 3 43 31 AM

Added a commit

Thanks again so much for your help :)

khuezy commented 7 months ago

You have to check the cloudwatch logs for the error message.

ziggy6792 commented 7 months ago

Hey, do you mean the cloudwatch logs for the lambda server function? There are none

Thanks :)

khuezy commented 7 months ago

There should be logs somewhere in the log groups. Trying using: https://docs.sst.dev/constructs/NextjsSite#logging

ziggy6792 commented 7 months ago

Thanks, I tried that. But I think that only combines the logs for different routes. I don't see any logs so its not useful.

Also, trpc is not the issue as when I totally remove it I get the same issue (returning null) Commit here

If anyone has an example of open next with the new apps directory that would also be great as maybe I could work forward from there.

Edit: Found this, will try https://github.com/sst/open-next/tree/main/examples/app-router

ziggy6792 commented 7 months ago

Hey @khuezy

After a long slog I fixed it. Using this for reference helped a lot

In the end all I had to do was upgrade to the latest open-next (now using it as a dev dependency) and a few other packages. Commit here

FYI I did also get it working with

experimental: {
  streaming: true,
}

But for this you also need to use streaming arg like this

"openbuild": "open-next build --streaming",

Thanks

khuezy commented 7 months ago

You shouldn't need to set buildCommand unless you have a specific need for it. Most of the props (except minify) are exposed via NextjsSite. The reason why it's used in the examples is b/c it has to reference open-next itself.