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! :(

asked a year ago95 views
No Answers

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.

Guidelines for Answering Questions