# tech9-cdk-nextjs-standalone

> Deploy a NextJS app to AWS using CDK. Uses standalone build and output tracing.

Latest version **0.0.9** (published 2023-06-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install tech9-cdk-nextjs-standalone
pnpm add tech9-cdk-nextjs-standalone
yarn add tech9-cdk-nextjs-standalone
bun add tech9-cdk-nextjs-standalone
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; large bundle; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2023-06-16 |
| First published | 2023-03-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 17 |
| Unpacked size | 115.6 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 361 |
| Author | JetBridge |
| Maintainers | durgaprasad |
| Keywords | aws, aws-cdk, cdk, cloud, iac, infrastructure, next, nextjs, serverless, standalone |

## Links

- npm: https://www.npmjs.com/package/tech9-cdk-nextjs-standalone
- Repository: https://github.com/jetbridge/cdk-nextjs
- Homepage: https://github.com/jetbridge/cdk-nextjs#readme
- Issues: https://github.com/jetbridge/cdk-nextjs/issues
- npm.io page: https://npm.io/package/tech9-cdk-nextjs-standalone

## Dependencies (17)

- [glob](https://npm.io/package/glob.md) ^8.1.0
- [jszip](https://npm.io/package/jszip.md) ^3.10.1
- [esbuild](https://npm.io/package/esbuild.md) 0.17.16
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.1.0
- [aws-lambda](https://npm.io/package/aws-lambda.md) ^1.0.7
- [micromatch](https://npm.io/package/micromatch.md) ^4.0.5
- [node-fetch](https://npm.io/package/node-fetch.md) ^3.3.1
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.3
- [indent-string](https://npm.io/package/indent-string.md) *
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^9.0.13
- [serverless-http](https://npm.io/package/serverless-http.md) ^3.2.0
- [@types/aws-lambda](https://npm.io/package/@types/aws-lambda.md) ^8.10.114
- [@types/micromatch](https://npm.io/package/@types/micromatch.md) ^4.0.2
- [@aws-sdk/client-s3](https://npm.io/package/@aws-sdk/client-s3.md) ^3.310.0
- [@types/cross-spawn](https://npm.io/package/@types/cross-spawn.md) ^6.0.2
- [@aws-crypto/sha256-js](https://npm.io/package/@aws-crypto/sha256-js.md) ^4.0.0
- [@aws-sdk/signature-v4](https://npm.io/package/@aws-sdk/signature-v4.md) ^3.341.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2023-06-16
- 0.0.8 — 2023-06-16
- 0.0.7 — 2023-06-15
- 0.0.6 — 2023-06-15
- 0.0.5 — 2023-06-14
- 2.0.2 — 2023-03-21
- 2.0.1 — 2023-03-21
- 2.0.0 — 2023-03-21
- 0.0.0 — 2023-03-21

## README

# Deploy NextJS with CDK

[![View on Construct Hub](https://constructs.dev/badge?package=cdk-nextjs-standalone)](https://constructs.dev/packages/cdk-nextjs-standalone)

## What is this?

A CDK construct to deploy a NextJS app using AWS CDK.
Supported NextJs versions: >=12.3.0+ (includes 13.0.0+)

Uses the [standalone output](https://nextjs.org/docs/advanced-features/output-file-tracing) build mode.

## Quickstart

Add the dependency `esbuild@0.17.16` to your project along with `cdk-nextjs-standalone`.

```shell
npm install -D esbuild@0.17.16 cdk-nextjs-standalone
```

```ts
import path from 'path';
import { Nextjs } from 'cdk-nextjs-standalone';

new Nextjs(this, 'Web', {
  nextjsPath: './web', // relative path to nextjs project root
});
```

## Documentation

Available on [Construct Hub](https://constructs.dev/packages/cdk-nextjs-standalone/).

### Discord Chat

We're in the #open-next channel on the [Serverless Stack Discord](https://discord.gg/sst).

## About

Deploys a NextJs static site with server-side rendering and API support. Uses AWS lambda and CloudFront.

There is a new (since Next 12) [standalone output mode which uses output tracing](https://nextjs.org/docs/advanced-features/output-file-tracing) to generate a minimal server and static files.
This standalone server can be converted into a CloudFront distribution and a lambda handler that handles SSR, API, and routing.

The CloudFront default origin first checks S3 for static files and falls back to an HTTP origin using a lambda function URL.

## Benefits

This approach is most compatible with new NextJs features such as ESM configuration, [middleware](https://nextjs.org/docs/advanced-features/middleware), next-auth, and React server components ("appDir").

The unmaintained [@serverless-nextjs project](https://github.com/serverless-nextjs/serverless-next.js) uses the deprecated `serverless` NextJs build target which [prevents the use of new features](https://github.com/serverless-nextjs/serverless-next.js/pull/2478).
This construct was created to use the new `standalone` output build and newer AWS features like lambda function URLs and fallback origins.

You may want to look at [Serverless Stack](https://sst.dev) and its [NextjsSite](https://docs.sst.dev/constructs/NextjsSite) construct for an improved developer experience if you are building serverless applications on CDK.

## Dependencies

Built on top of [open-next](https://open-next.js.org/), which was partially built using the original core of cdk-nextjs-standalone.

## Heavily based on

- [Open-next](https://open-next.js.org/)
- <https://github.com/iiroj/iiro.fi/commit/bd43222032d0dbb765e1111825f64dbb5db851d9>
- <https://github.com/sladg/nextjs-lambda>
- <https://github.com/serverless-nextjs/serverless-next.js/tree/master/packages/compat-layers/apigw-lambda-compat>
- [Serverless Stack](https://github.com/serverless-stack/sst)
  - [RemixSite](https://github.com/serverless-stack/sst/blob/master/packages/resources/src/NextjsSite.ts) construct
  - [NextjsSite](https://github.com/serverless-stack/sst/blob/master/packages/resources/src/RemixSite.ts) construct

## Contribute

Hey there, we value every new contribution a lot 🙏🏼 thank you.

Here is a short HowTo before you get started:

1. Please make sure to create a bug first
2. Link the bug in your pull request
3. Run `yarn build` after you made your changes and before you open a pull request

## Breaking changes

- v3.0.0: Using open-next for building, ARM64 architecture for image handling, new build options.

- v2.0.0: SST wrapper changed, lambda/assets/distribution defaults now are in the `defaults` prop, refactored distribution settings into the new NextjsDistribution construct. If you are upgrading, you must temporarily remove the `customDomain` on your existing 1.x.x app before upgrading to >=2.x.x because the CloudFront distribution will get recreated due to refactoring, and the custom domain must be globally unique across all CloudFront distributions. Prepare for downtime.

---
_Source: https://npm.io/package/tech9-cdk-nextjs-standalone · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
