From 62ac7d27d7ab671c5ff67aaf0bc070c799120661 Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 12 Mar 2025 12:00:23 +0100 Subject: [PATCH 1/9] routing --- pages/aws/inner_workings/routing.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pages/aws/inner_workings/routing.mdx b/pages/aws/inner_workings/routing.mdx index 11e762a..630ff0c 100644 --- a/pages/aws/inner_workings/routing.mdx +++ b/pages/aws/inner_workings/routing.mdx @@ -19,3 +19,18 @@ Here is a list of features that OpenNext routing system handle: #### Next Middleware The Next middleware in OpenNext is not running in the same way as in Next.js. In Next.js, the middleware is running inside the `NextServer` inside a fake edge runtime. In OpenNext, we modify the middleware and run it fully inside the routing layer. So if you run the routing layer in Node, you can use Node api inside the middleware (it's a bit tricky because it won't work with `next dev` and involves some workaround because Next will remove Node api during bundling. Some example [here](/aws/config/custom_overrides#define-a-global-to-use-node-in-the-middleware)). + +On latest Next 15(works with latest OpenNext aswell) you can now add an `experimental` setting in `next.config.ts` to enable `nodejs` as the runtime for the middleware: +```ts +const nextConfig: NextConfig = { + experimental: { + nodeMiddleware: true, + }, +}; +// and then in your `middleware.ts` you put: +export const config = { + runtime: 'nodejs', +}; +``` + +Here is the [PR](https://github.com/vercel/next.js/pull/75624) that introduced this feature in Next. \ No newline at end of file From 7d34ae9118b53500fa2424d97c97c5533a3f4b09 Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 12 Mar 2025 12:00:19 +0100 Subject: [PATCH 2/9] caching --- pages/aws/inner_workings/caching.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/aws/inner_workings/caching.mdx b/pages/aws/inner_workings/caching.mdx index 71cc0b6..2344ecd 100644 --- a/pages/aws/inner_workings/caching.mdx +++ b/pages/aws/inner_workings/caching.mdx @@ -1,6 +1,6 @@ ## Caching in Next and OpenNext -Caching could be become tricky very fast when using Next outside of Vercel. There is a lot of things that need to be taken into account. +Caching could become tricky very fast when using Next outside of Vercel. There is a lot of things that need to be taken into account. Usually, you'll deploy your Next app with a CDN in front of it. This CDN will cache the responses from your Next app and serve them to the users. This is great for performance, but it can also be a problem when you need to invalidate the cache. We provide some code examples in this doc to help with [cloudfront cache invalidation](#cloudfront-cache-invalidation). **In OpenNext, you only need to do this if you do On Demand Revalidation**. From a42460188ee17fa1cba063ea0cabdbcf41c3a861 Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 12 Mar 2025 12:00:15 +0100 Subject: [PATCH 3/9] inner working --- pages/aws/inner_workings.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/aws/inner_workings.mdx b/pages/aws/inner_workings.mdx index fb4c724..f6f8ec7 100644 --- a/pages/aws/inner_workings.mdx +++ b/pages/aws/inner_workings.mdx @@ -19,5 +19,5 @@ my-next-app/ revalidation-function/ -> Handler code for revalidation backend image-optimization-function/ -> Handler code for image optimization backend warmer-function/ -> Cron job code to keep server function warm - Not mandatory - dynamo-provider/ -> Code for a custom resource to populate the Tag Cache - Only necessary for app dir + dynamodb-provider/ -> Code for a custom resource to populate the Tag Cache - Only necessary for app dir ``` From a8342a2f2dcb19eb8f87319ca1beac974386aeea Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 12 Mar 2025 12:00:11 +0100 Subject: [PATCH 4/9] comparison --- pages/aws/comparison.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/aws/comparison.mdx b/pages/aws/comparison.mdx index 1f0a522..a229c26 100644 --- a/pages/aws/comparison.mdx +++ b/pages/aws/comparison.mdx @@ -1,4 +1,4 @@ -It should be noted that open-next does not actually deploy the app. It only bundles everything for your IAC to deploy it. +It should be noted that OpenNext does not actually deploy the app. It only bundles everything for your IAC to deploy it. Here is a table comparing the different options to deploy a next.js app: From 477f2f17dc6e97023989606041b0e6ea76cfac6d Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 12 Mar 2025 12:25:23 +0100 Subject: [PATCH 5/9] common issues --- pages/aws/common_issues.mdx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index 79b3dc5..d15fa39 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -99,3 +99,14 @@ export const initSentry = (runtime: "nodejs" | "edge") => { }); }; ``` + +#### Empty body in response when streaming in AWS Lambda + +We have seen trouble in the past with streaming hanging in AWS Lambda when the response body is empty. +We currently have a workaround in OpenNext for this by setting the environment variable `OPEN_NEXT_FORCE_NON_EMPTY_RESPONSE` to `true`. +This will write something to the stream to make sure it is not empty. + +#### The Yarn Plug'n'Play manifest forbids importing "urlpattern-polyfill" here because it's not listed as a dependency of this package + +This error is usually resolved by removing all yarn files in your repo. You should also look in your `package.json` and see if you have `yarn` set as `packageManager` there. Removing it will solve the issue. +If you use `yarn` there is a workaround [here](https://stackoverflow.com/a/76902985https://stackoverflow.com/a/76902985). From 7d9b0a9b51fee56f2509089cbdb0ff7f69172e51 Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 12 Mar 2025 17:46:22 +0100 Subject: [PATCH 6/9] lint --- pages/aws/inner_workings/routing.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pages/aws/inner_workings/routing.mdx b/pages/aws/inner_workings/routing.mdx index 630ff0c..fcb4cb6 100644 --- a/pages/aws/inner_workings/routing.mdx +++ b/pages/aws/inner_workings/routing.mdx @@ -21,6 +21,7 @@ Here is a list of features that OpenNext routing system handle: The Next middleware in OpenNext is not running in the same way as in Next.js. In Next.js, the middleware is running inside the `NextServer` inside a fake edge runtime. In OpenNext, we modify the middleware and run it fully inside the routing layer. So if you run the routing layer in Node, you can use Node api inside the middleware (it's a bit tricky because it won't work with `next dev` and involves some workaround because Next will remove Node api during bundling. Some example [here](/aws/config/custom_overrides#define-a-global-to-use-node-in-the-middleware)). On latest Next 15(works with latest OpenNext aswell) you can now add an `experimental` setting in `next.config.ts` to enable `nodejs` as the runtime for the middleware: + ```ts const nextConfig: NextConfig = { experimental: { @@ -29,8 +30,8 @@ const nextConfig: NextConfig = { }; // and then in your `middleware.ts` you put: export const config = { - runtime: 'nodejs', + runtime: "nodejs", }; ``` -Here is the [PR](https://github.com/vercel/next.js/pull/75624) that introduced this feature in Next. \ No newline at end of file +Here is the [PR](https://github.com/vercel/next.js/pull/75624) that introduced this feature in Next. From ea7cddf0228f8ac1a2f0d892de38e3e348b5f073 Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 13 Mar 2025 19:22:32 +0100 Subject: [PATCH 7/9] yarn issue update --- pages/aws/common_issues.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index d15fa39..dd6a349 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -106,7 +106,9 @@ We have seen trouble in the past with streaming hanging in AWS Lambda when the r We currently have a workaround in OpenNext for this by setting the environment variable `OPEN_NEXT_FORCE_NON_EMPTY_RESPONSE` to `true`. This will write something to the stream to make sure it is not empty. -#### The Yarn Plug'n'Play manifest forbids importing "urlpattern-polyfill" here because it's not listed as a dependency of this package +#### The Yarn Plug'n'Play manifest forbids importing "xxx" here because it's not listed as a dependency of this package This error is usually resolved by removing all yarn files in your repo. You should also look in your `package.json` and see if you have `yarn` set as `packageManager` there. Removing it will solve the issue. If you use `yarn` there is a workaround [here](https://stackoverflow.com/a/76902985https://stackoverflow.com/a/76902985). + +This error, and other issues related to `yarn` if your not using it might be solved by updating `nvm` to `0.40.2` or try running `corepack disable`. From 36761f157dc68a1047ea48e4dc5fb75eeacfd937 Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 13 Mar 2025 19:28:27 +0100 Subject: [PATCH 8/9] english --- pages/aws/common_issues.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index dd6a349..24daf60 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -111,4 +111,4 @@ This will write something to the stream to make sure it is not empty. This error is usually resolved by removing all yarn files in your repo. You should also look in your `package.json` and see if you have `yarn` set as `packageManager` there. Removing it will solve the issue. If you use `yarn` there is a workaround [here](https://stackoverflow.com/a/76902985https://stackoverflow.com/a/76902985). -This error, and other issues related to `yarn` if your not using it might be solved by updating `nvm` to `0.40.2` or try running `corepack disable`. +If you are not using `yarn` and you see `yarn` related errors it might be solved by running `corepack disable` or updating `nvm` to `0.40.2`. \ No newline at end of file From 5b08031658f9cf78f8cebc36cb0e2837af98f230 Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 13 Mar 2025 19:31:09 +0100 Subject: [PATCH 9/9] prettier --- pages/aws/common_issues.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index 24daf60..0cf33cb 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -111,4 +111,4 @@ This will write something to the stream to make sure it is not empty. This error is usually resolved by removing all yarn files in your repo. You should also look in your `package.json` and see if you have `yarn` set as `packageManager` there. Removing it will solve the issue. If you use `yarn` there is a workaround [here](https://stackoverflow.com/a/76902985https://stackoverflow.com/a/76902985). -If you are not using `yarn` and you see `yarn` related errors it might be solved by running `corepack disable` or updating `nvm` to `0.40.2`. \ No newline at end of file +If you are not using `yarn` and you see `yarn` related errors it might be solved by running `corepack disable` or updating `nvm` to `0.40.2`.