aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
450 stars 113 forks source link

Cannot turn off access control for the Next.js app #3133

Closed april-swellfox closed 1 year ago

april-swellfox commented 1 year ago

Before opening, please confirm:

App Id

dk0lb4vk3xvnt

AWS Region

us-east-1

Amplify Hosting feature

Frontend builds

Describe the bug

My app is now running Next 13. Locally, this works great. When it is almost done building, it gets this error: Invalid next.config.js options detected.

frontend-build-error

My next.config.js does not have target property:

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  images: {
    domains: [
      's3.us-east-1.amazonaws.com',
      '[removed].cloudfront.net',
    ],
  },
};

module.exports = nextConfig;

It seems like Amplify is adding the target property to next.config.js which is not supported in Next 13.

Expected behavior

It should build successfully.

Reproduction steps

  1. Push commit to Github or Redeploy this version
  2. It will start to build and it will fail.

Build Settings

version: 1

backend:
  phases:
    preBuild:
      commands:
        - npm i -g @aws-amplify/cli@10.5.1 
    build:
      commands:
        - amplifyPush --simple

frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
        - echo "JSON_URL=$JSON_URL" >> .env.local
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*
      - .next/cache/**/*

Log output

``` # Put your logs below this line ├ chunks/framework-2fe4cb6473b20297.js 45.4 kB ├ chunks/main-415240f83ca52e31.js 26.8 kB ├ chunks/pages/_app-f764a9d0c4b9e6ba.js 139 kB ├ chunks/webpack-344ff976107fe7be.js 1.05 kB └ css/bd655dc44a0722c8.css 10.3 kB 2022-11-22T09:03:16.236Z [INFO]: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps) ○ (Static) automatically rendered as static HTML (uses no initial props) ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps) (ISR) incremental static regeneration (uses revalidate in getStaticProps) 2022-11-22T09:03:16.403Z [INFO]: # Executing command: echo "JSON_URL=" >> .env.local 2022-11-22T09:03:16.403Z [INFO]: Starting SSR Build... 2022-11-22T09:04:09.123Z [ERROR]: Error: Command failed with exit code 1: node_modules/.bin/next build warn - Invalid next.config.js options detected: - The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack). See more info here: https://nextjs.org/docs/messages/invalid-next-config > 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 Object.loadConfig [as default] (/codebuild/output/src439763728/src/me-mini-sites/node_modules/next/dist/server/config.js:96:19) at async Span.traceAsyncFn (/codebuild/output/src439763728/src/me-mini-sites/node_modules/next/dist/trace/trace.js:79:20) at async /codebuild/output/src439763728/src/me-mini-sites/node_modules/next/dist/build/index.js:69:28 at async Span.traceAsyncFn (/codebuild/output/src439763728/src/me-mini-sites/node_modules/next/dist/trace/trace.js:79:20) at async Object.build [as default] (/codebuild/output/src439763728/src/me-mini-sites/node_modules/next/dist/build/index.js:65:29) info - Loaded env from /codebuild/output/src439763728/src/me-mini-sites/.env.local at makeError (/root/.//node_modules/execa/lib/error.js:60:11) at handlePromise (/root/.//node_modules/execa/index.js:118:26) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Builder.build (/root/.//node_modules/@sls-next/lambda-at-edge/dist/build.js:377:13) at async NextjsComponent.build (/root/.//node_modules/@sls-next/-component/dist/component.js:165:13) at async NextjsComponent.default (/root/.//node_modules/@sls-next/-component/dist/component.js:22:13) at async fn (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/utils.js:280:41) at async Promise.all (index 0) at async executeGraph (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/utils.js:294:3) at async Template.default (/root/.npm/_npx/780a6c1398234b48/node_modules/@/template/.js:67:38) at async Object.runComponents (/root/.npm/_npx/780a6c1398234b48/node_modules/@/cli/src/index.js:222:17) { shortMessage: 'Command failed with exit code 1: node_modules/.bin/next build', command: 'node_modules/.bin/next build', escapedCommand: '"node_modules/.bin/next" build', exitCode: 1, signal: undefined, signalDescription: undefined, stdout: 'info - Loaded env from /codebuild/output/src439763728/src/me-mini-sites/.env.local', stderr: 'warn - Invalid next.config.js options detected: \n' + ' - The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).\n' + '\n' + 'See more info here: https://nextjs.org/docs/messages/invalid-next-config\n' + '\n' + '> Build error occurred\n' + 'Error: The "target" property is no longer supported in next.config.js.\n' + 'See more info here https://nextjs.org/docs/messages/deprecated-target-config\n' + ' at Object.loadConfig [as default] (/codebuild/output/src439763728/src/me-mini-sites/node_modules/next/dist/server/config.js:96:19)\n' + ```

Additional information

No response

calavera commented 1 year ago

Hi,

If you created your application before last Thursday, you'll need to follow this migration guide to deploy your Next.js 13 app: https://docs.aws.amazon.com/amplify/latest/userguide/update-app-nextjs-version.html

april-swellfox commented 1 year ago

Thank you for your reply.

I followed the instructions and it built automatically to the main branch and it was successful. My latest updates are actually in a different branch. I redeployed that particular branch and build was still successful. But this branch has an access control settings and it doesn't seem to accept the correct username and password.

So I removed the access control settings for that branch. Redeploy this version button is no longer available. (I just found out that it takes a few minutes to see the button again). I created a webhook for this particular branch to trigger a build. Again build was successful and the access control still prompts me to enter the username and password. I tried different browsers but still the same.

I redeployed the branch several times and same thing happened, the prompt was still there. It seems that the build ignores the access control settings.

access-control-prompt

swaminator commented 1 year ago

@april-swellfox can you share your basic auth settings. Have you enabled it globally by any chance?

april-swellfox commented 1 year ago

No, global password is unchecked. My main and develop branches are restricted but that specific branch is publicly viewable.

access-control-settings

april-swellfox commented 1 year ago

I pushed again just to trigger a build and it's still the same, build is successful and the prompt is still there.

saadataz commented 1 year ago

@april-swellfox. april branch still not migrated. You need to migrate the branches individually. Can you please try migrating the april branch to Hosting Compute as described here https://docs.aws.amazon.com/amplify/latest/userguide/update-app-nextjs-version.html

april-swellfox commented 1 year ago

I actually updated my main branch since that migrated successfully. It does have an access control but won't accept my username and password and I'm sure I typed the correct username and password.

april-swellfox commented 1 year ago

Where can I see the banner with the Migrate button? I can't see it.

april-swellfox commented 1 year ago

I created a new branch and hosted it, so it doesn't have an access control. But when it is done deploying and opened the link, there's an access control prompt.

ghost commented 1 year ago

Thank you for the updates @april-swellfox we are continuing to investigate this behavior on our end and will provide an update shortly.

ghost commented 1 year ago

Hi @april-swellfox There is a rewrite rule in your application that directs traffic to the old CloudFront distribution used prior to migrating. The requests are being made to that distribution which stores the old access control credentials - this is why your new credentials are not working. Ideally, this rule would have been deleted in the migration process but this appears to be a bug.

You can resolve this issue by navigating to App settings -> Rewrites and redirects and removing the rule.

Please let us know if removing this rule has resolved the issue for you. Thank you for your patience and we apologize for this inconvenience.

april-swellfox commented 1 year ago

@hloriana That worked! Thank you!

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.