Nx with Next.js (integrated monorepo) - the standalone directory missing a server.js file.

0

Hi,

I'm struggling with problem connected with hosting on AWS Amplify my app Next.js app from Nx integrated monorepo. Main problem (at least in my opinion) is with locating by Amplify server.js file which is not located where expected by default (directly in standalone directory) but deeper in standalone/apps/the-foxxes-music. I have no idea how to define this path and Im receiving error log like this:

2023-05-24T06:29:54.974Z [INFO]: # Completed phase: build
                                 ## Completed Frontend Build
2023-05-24T06:29:54.976Z [INFO]: ## Build completed successfully
2023-05-24T06:29:54.977Z [INFO]: # Starting caching...
2023-05-24T06:29:54.987Z [INFO]: # Creating cache artifact...
2023-05-24T06:30:03.617Z [INFO]: # Created cache artifact
2023-05-24T06:30:03.700Z [INFO]: # Uploading cache artifact...
2023-05-24T06:30:08.144Z [INFO]: # Uploaded cache artifact
2023-05-24T06:30:08.267Z [INFO]: # Caching completed
2023-05-24T06:30:08.270Z [INFO]: Setting NEXT_PRIVATE_STANDALONE=true to produce .next/standalone directory
2023-05-24T06:30:08.274Z [INFO]: # No custom headers found.
2023-05-24T06:30:08.278Z [ERROR]: !!! CustomerError: The standalone directory /codebuild/output/src950288398/src/the-foxxes-music/dist/apps/the-foxxes-music/.next/standalone is missing a server.js file. This file shoud have been created automatically by NextJS. Make sure you enable output standalone on your next.config.js file or set NEXT_PRIVATE_STANDALONE=true. https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files
2023-05-24T06:30:08.278Z [INFO]: # Starting environment caching...
2023-05-24T06:30:08.278Z [INFO]: # Environment caching completed
Terminating logging...

My yml:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: dist/apps/the-foxxes-music/.next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

My next.config.js:

//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
const path = require('path');

/**
 * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = {
  nx: {
    // Set this to true if you would like to use SVGR
    // See: https://github.com/gregberge/svgr
    svgr: false,
  },
  output: 'standalone',
  experimental: {
    outputFileTracingRoot: path.join(__dirname, '../../'),
  },
};

const plugins = [
  // Add more Next.js plugins to this list if needed.
  withNx,
];

module.exports = composePlugins(...plugins)(nextConfig);

And output structure: Output structure

HELP PLEASE! :(

질문됨 일 년 전98회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠