From da278fcc0658d5c68540cf2574a3811ddeafd209 Mon Sep 17 00:00:00 2001 From: magnus Date: Wed, 2 Apr 2025 10:57:03 +0200 Subject: [PATCH 1/5] add outputFileTracingIncludes to common issues --- pages/aws/common_issues.mdx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index 2117c1f..fa8cb63 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -112,3 +112,26 @@ This error is usually resolved by removing all yarn files in your repo. You shou If you use `yarn` there is a workaround [here](https://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`. + +#### A file/dependency is missing from my bundle + +Sometimes there might be a file missing from your server functions bundle. An example could be `sentry.server.config.ts`. In Next there is an option to include files that were not picked up by tracing. +Its called `outputFileTracingIncludes`. Here is an example on how to use it in `next.config.ts`: + +```ts +import type { NextConfig } from "next"; + +const nextConfig: NextConfig = { + /* config options here */ + outputFileTracingIncludes: { + "*": ["sentry.server.config.ts"], + }, +}; + +export default nextConfig; +``` + +This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`. To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). + +It works with splitting the functions in OpenNext aswell. If your key corresponds to a specific route (i.e `api/test`), it will only get copied into that functions bundle. However, using `*` will copy it into every function bundle. It will also work in a monorepo. +Lets say you have your Next app in `packages/web`, the file will be written to: `packages/web/.open-next/server-functions/default/packages/web/sentry.server.config.ts` From 0a06898a2308a4fb43e67abde4652dbdadff0e9b Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 3 Apr 2025 10:43:02 +0200 Subject: [PATCH 2/5] review --- pages/aws/common_issues.mdx | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index fa8cb63..a64fe7c 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -115,7 +115,7 @@ If you are not using `yarn` and you see `yarn` related errors it might be solved #### A file/dependency is missing from my bundle -Sometimes there might be a file missing from your server functions bundle. An example could be `sentry.server.config.ts`. In Next there is an option to include files that were not picked up by tracing. +Sometimes there might be a file missing from your server functions bundle. An example could be `sentry.server.config.ts`. It can be any file or directory and it also accept globs. In Next there is an option to include files that were not picked up by tracing. Its called `outputFileTracingIncludes`. Here is an example on how to use it in `next.config.ts`: ```ts @@ -125,13 +125,44 @@ const nextConfig: NextConfig = { /* config options here */ outputFileTracingIncludes: { "*": ["sentry.server.config.ts"], + // can also be a glob pattern + "/api/*": ["node_modules/.prisma/client/**/*"], }, }; export default nextConfig; ``` -This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`. To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). +This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`, or every splitted function in this case. To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). -It works with splitting the functions in OpenNext aswell. If your key corresponds to a specific route (i.e `api/test`), it will only get copied into that functions bundle. However, using `*` will copy it into every function bundle. It will also work in a monorepo. -Lets say you have your Next app in `packages/web`, the file will be written to: `packages/web/.open-next/server-functions/default/packages/web/sentry.server.config.ts` +It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e `api/test`), it will only get copied into that functions bundle. However, using `*` as key will copy it into every function bundle. Here is an example with function splitting: + +```ts +// open-next.config.ts +import type { OpenNextConfig } from "@opennextjs/aws/types/open-next"; +const config = { + default: {}, + functions: { + extraFunction: { + patterns: ["api/test"], + // this is the route that will be used in this function + routes: ["app/api/test/route"], + override: { + wrapper: "aws-lambda-streaming", + }, + }, + }, +} satisfies OpenNextConfig; + +// next.config.ts +import type { NextConfig } from "next"; + +const nextConfig: NextConfig = { + outputFileTracingIncludes: { + // these files will be copied only to the extraFunction bundle + "/api/test": ["sentry.config.ts", "node_modules/.prisma/client/**/*"], + }, +}; +``` + +It will also work in a monorepo. Lets say you have your Next app in `packages/web`, the files will be written to: `packages/web/.open-next/server-functions/default/packages/web/*` From d2731d748f2504ce42a5177a7c8995305708ca1a Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 3 Apr 2025 10:47:40 +0200 Subject: [PATCH 3/5] fix --- 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 a64fe7c..c5677ec 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -135,7 +135,7 @@ export default nextConfig; This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`, or every splitted function in this case. To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). -It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e `api/test`), it will only get copied into that functions bundle. However, using `*` as key will copy it into every function bundle. Here is an example with function splitting: +It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e `api/test`), it will only get copied into the functions bundle that has that route. However, using `*` as key will copy it into every function bundle. Here is an example with function splitting: ```ts // open-next.config.ts From 1961414065f4b4d7be80513994a2195b41aedaf3 Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 3 Apr 2025 10:50:54 +0200 Subject: [PATCH 4/5] shorter --- pages/aws/common_issues.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index c5677ec..62baf13 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -135,8 +135,7 @@ export default nextConfig; This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`, or every splitted function in this case. To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). -It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e `api/test`), it will only get copied into the functions bundle that has that route. However, using `*` as key will copy it into every function bundle. Here is an example with function splitting: - +It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e: `api/test`), it will be included only in the function bundle for that route. Using `*` as a key, however, will include it in every function bundle. Here is an example with function splitting: ```ts // open-next.config.ts import type { OpenNextConfig } from "@opennextjs/aws/types/open-next"; From f1e0f04607b64d2c52e02d9a0220482323113d1b Mon Sep 17 00:00:00 2001 From: magnus Date: Thu, 3 Apr 2025 10:57:38 +0200 Subject: [PATCH 5/5] prettier --- pages/aws/common_issues.mdx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index 62baf13..c0d27e9 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -133,9 +133,12 @@ const nextConfig: NextConfig = { export default nextConfig; ``` -This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`, or every splitted function in this case. To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). +This will copy the file to `.open-next/server-functions/default/sentry.server.config.ts`, or every splitted function in this case. +To read more about `outputFileTracingIncludes` you can refer to the [Next.js documentation](https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats). + +It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e: `api/test`), it will be included only in the function bundle for that route. +Using `*` as a key, however, will include it in every function bundle. Here is an example with function splitting: -It works with function splitting in OpenNext aswell. If your key corresponds to a specific route (i.e: `api/test`), it will be included only in the function bundle for that route. Using `*` as a key, however, will include it in every function bundle. Here is an example with function splitting: ```ts // open-next.config.ts import type { OpenNextConfig } from "@opennextjs/aws/types/open-next";