diff --git a/pages/aws/common_issues.mdx b/pages/aws/common_issues.mdx index 2117c1f..c0d27e9 100644 --- a/pages/aws/common_issues.mdx +++ b/pages/aws/common_issues.mdx @@ -112,3 +112,59 @@ 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`. 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 +import type { NextConfig } from "next"; + +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`, 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: + +```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/*`