Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
khuezy committed Oct 12, 2023
1 parent 6efbc25 commit 54a150b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/pages/common_issues.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ If you are using sentry, API routes returns empty body. You could try configurin

#### My ISR page has this cache-control header `s-maxage=2, stale-while-revalidate=2592000`

Given how ISR works, while waiting for the revalidation to happen, the page will be served using this cache control header. This prevent your server from being overloaded by a lot of requests while the revalidation is done. You can read more about it [here](/inner_workings/isr).
Given how ISR works, while waiting for the revalidation to happen, the page will be served using this cache control header. This prevent your server from being overloaded by a lot of requests while the revalidation is done. You can read more about it [here](/inner_workings/isr).

#### Unzipped size must be smaller than 262144000 bytes

AWS Lambda has an unzipped size limit of 250MB. If your app is over this limit, then it is most likely using a node_module library that is too large for serverless or there is a large dev dependency getting bundled.
For example, `pdfjs` has `canvas` optional dependency which takes up 180MB. For more details, [read me](/common_issues/bundle_size)
39 changes: 39 additions & 0 deletions docs/pages/common_issues/bundle_size.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {Callout} from 'nextra/components'


#### Reducing Bundle Size

Next will incorrectly trace dev dependencies to be included in the output `node_modules`, which will significantly increase the lambda bundle. For example, the @swc/core-\* binary is ~33MB!

Add this to your next.config.js to help minimize the lambda bundle size:

```typescript
outputFileTracingExcludes: {
'*': [
'@swc/core',
'esbuild',
'uglify-js',
'watchpack',
'webassemblyjs'
],
},
```

<Callout type="warning" emoji="⚠️">
NextJS currently doesn't expose `outputFileTracingExcludes` as an environmental variable so `open-next`cannot programmatically set this like it does for`output`and`outputFileTracingRoot`.
Currently, next uses `webpack` to trace server actions, so you shouldn't add `webpack` to the excludes list, otherwise it will break server actions.
</Callout>

#### Unzipped size must be smaller than 262144000 bytes

To identify the module that's taking up too much space (and isn't serverless friendly):

```bash
du -hs .open-next/server-function/node_modules/* | sort -rh
```

If your app requires the offending library, then consider moving your business logic of the `api` to its own lambda, eg: `/api/v2` => `Api Lambda`

<Callout type="info" emoji="ℹ️">
There is a [PR](https://github.com/sst/open-next/pull/242) to remove some dev dependency from the output node_modules but that requires more testing before it can merge.
</Callout>

0 comments on commit 54a150b

Please sign in to comment.