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

posta un anno fa98 visualizzazioni
Nessuna risposta

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande