aws-amplify / aws-amplify/amplify-hosting

[Next.js 14] Cannot build static next.js app with next.config.js `output` property

Open
#3,840 4 comments 2 reactions 0 assignees View on GitHub
pending-triage
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-js/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-js/discussions).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-js/blob/main/CONTRIBUTING.md#bug-reports).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### JavaScript Framework

Next.js

### Amplify APIs

Not applicable

### Amplify Categories

Not applicable

### Environment information

**Local**
```
System:
OS: macOS 14.1.2
CPU: (12) arm64 Apple M2 Pro
Memory: 4.06 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/.volta/tools/image/node/20.9.0/bin/node
npm: 10.1.0 - ~/.volta/tools/image/node/20.9.0/bin/npm
Browsers:
Chrome: 119.0.6045.199
Safari: 17.1.2
npmGlobalPackages:
corepack: 0.20.0
npm: 10.1.0

```

### Describe the bug

https://nextjs.org/docs/app/building-your-application/deploying/static-exports#version-history

> v14.0.0 | next export has been removed in favor of "output": "export"

I changed `next.config.js` for the above changes and pushed codes and the build failed.

> Error: The "target" property is no longer supported in next.config.js.

I got the above error even though I set `output` without setting `target`.
I assume this is due to the amplify adapter setting `target`.

### Expected behavior

No error.

### Reproduction steps

1. Install next.js 14.
2. update next.config.js  "output": "export".
3. (maybe not needed) Change build config in web console. Amazon Linux 2023 / Node.js 18 / Next.js latest
4. build fail.

### Code Snippet

```javascript
const nextConfig = {
output: 'export',
};

module.exports = nextConfig;

```

### Log output

```
2023-12-05T11:04:52.009Z [INFO]: ✓ Generating static pages (18/18)
2023-12-05T11:04:54.416Z [INFO]: Finalizing page optimization ...
2023-12-05T11:04:54.418Z [INFO]: Collecting build traces ...
2023-12-05T11:05:02.821Z [INFO]:
2023-12-05T11:05:02.825Z [INFO]: Route (pages) Size First Load JS
┌ ○ / 3.15 kB 301 kB
├ └ css/9527f07cb9002c6e.css 1.63 kB
├ ○ /login 293 B 281 kB
└ ○ /options/[optionId]/conditions 710 B 301 kB
+ First Load JS shared by all 284 kB
├ chunks/framework-b31dd959a3bdfd87.js 45.2 kB
├ chunks/main-5d0d6ee21df7e9ec.js 37 kB
├ chunks/pages/_app-4f1b59ce64023ea0.js 196 kB
├ chunks/webpack-b8864f50dd6e41e7.js 2.17 kB
└ css/f6c36e6fc4d05c86.css 2.6 kB
2023-12-05T11:05:02.826Z [INFO]: ○ (Static) prerendered as static content
2023-12-05T11:05:02.879Z [INFO]: Starting SSR Build...
2023-12-05T11:06:25.115Z [ERROR]: Error: Command failed with exit code 1: node_modules/.bin/next build
> Build error occurred
Error: The "target" property is no longer supported in next.config.js.
See more info here https://nextjs.org/docs/messages/deprecated-target-config
at loadConfig (/codebuild/output/src816863117/src/NS-app/frontend/grantee/node_modules/next/dist/server/config.js:744:19)

```

### aws-exports.js

_No response_

### Manual configuration

_No response_

### Additional configuration

_No response_

### Mobile Device

_No response_

### Mobile Operating System

_No response_

### Mobile Browser

_No response_

### Mobile Browser Version

_No response_

### Additional information and screenshots

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the reported next.config.js setting and reproduce the failure by running next build with Next.js 14 and output: 'export'. Trace the Amplify Hosting build path shown in the log to identify where the deprecated target property is added; done means the static build completes without the target-config error.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, node.js
Domain
build-system, ci-cd, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.