Skip to content

Failed to copy traced files for /codebuild/output/

0

While trying to build/deploy my next.js 15 app on Amplify, the build is failing due to insufficient permissions. I've tried multiple ways and its not working. My next.js app utilizes SSR.

The Error: Enter image description here

My amplify.yam

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - corepack enable
        - yarn set version 4.5.2
    build:
      commands:
        - yarn install
        - yarn build
  artifacts:
    baseDirectory: .next
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

My Next Config

const nextConfig = {
    compiler: {
      styledComponents: true,
    },
    productionBrowserSourceMaps: false,
    outputFileTracingRoot: undefined,
    images: {
      remotePatterns: [
        {
          hostname: 'firebasestorage.googleapis.com',
          protocol: 'https',
        },
        {
          hostname: 'cloudflare-ipfs.com',
          protocol: 'https',
        },
        {
          protocol: "https",
          hostname: "images.unsplash.com",
        }
      ],
    },
    output: 'standalone',
    eslint: {
      ignoreDuringBuilds: true
    },
    redirects: async () => [],
  }
  module.exports = nextConfig

asked a year ago331 views

1 Answer
0

The error you're encountering suggests that there's an issue with permissions when trying to copy traced files during the build process. This is likely related to the output configuration in your Next.js setup.

To address this issue, try the following adjustments:

  1. Remove the 'output: 'standalone'' line from your Next.js configuration. The standalone output can sometimes cause issues with file tracing and permissions in certain deployment environments.

  2. Instead of using the '.next' directory as your baseDirectory in the amplify.yaml file, try using the following configuration:

artifacts:
  baseDirectory: /
  files:
    - '**/*'
  excludes:
    - some-excluded-file

This change allows Amplify to handle the file structure more flexibly.

  1. Ensure that your Amplify app has the necessary permissions to access and modify files in the build environment. You may need to check and update the IAM role associated with your Amplify app to include sufficient permissions for CodeBuild operations.

  2. If the issue persists, you might want to try setting the 'outputFileTracingRoot' in your Next.js config to the project root:

outputFileTracingRoot: path.join(__dirname),

These changes should help resolve the permission issues you're experiencing during the build process. If you continue to face problems, you may need to review your Amplify app's build settings and ensure all necessary permissions are in place.
Sources
Unable to pull container in CodeBuild project even with loose policy | AWS re:Post
AWS CodeBuild permissions reference - AWS CodeBuild
Allow users to interact with CodeBuild - AWS CodeBuild

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.