amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

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

Open matamatanot opened this issue 1 year ago • 4 comments

Before opening, please confirm:

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

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

matamatanot avatar Dec 05 '23 11:12 matamatanot

Hi @matamatanot thank you for opening this issue. I’m transferring it over to the Hosting repository for better assistance.

nadetastic avatar Dec 05 '23 15:12 nadetastic

updating the build image worked for me. https://github.com/aws-amplify/amplify-hosting/issues/3295#issuecomment-1843645331

saulonunesdev avatar Dec 06 '23 20:12 saulonunesdev

I changed AWS Linux 2023 and got an error that /usr/bin/aws: No such file or directory. Any idea where it was changed?

./update_amplify_redirections.sh

cat $OUTPUT_FILE /usr/local/bin/aws amplify update-app --app-id $AWS_APP_ID --custom-rules file://redirections.json

[WARNING]: ./update_amplify_redirections.sh: line 97: /usr/bin/aws: No such file or directory [ERROR]: !!! Build failed [ERROR]: !!! Error: Command failed with exit code 127

Edited: simply aws removing /usr/bin/. Success!

matamatanot avatar Feb 09 '24 14:02 matamatanot

Even if you use AWS Linux 2023, the build will fail. Even if the platform value is set to "Web", "platform": "WEB_DYNAMIC" is automatically set.

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

matamatanot avatar Feb 09 '24 16:02 matamatanot