opennextjs / opennextjs-aws

Open-source Next.js adapter for AWS
https://opennext.js.org
MIT License
4.41k stars 131 forks source link

No such file or directory page_client-reference-manifest.js with Route Groups #622

Closed moverware closed 2 weeks ago

moverware commented 2 weeks ago

I just migrated from app/central/... to app/(central)/... to share a layout but remove the url grouping, as explained in the nextjs docs here: https://nextjs.org/docs/app/building-your-application/routing/route-groups

But this breaks my SST deploy / OpenNext build. My dir layout is:

tree -L 2 app/
app/
├── (central)
│   ├── collection
│   ├── discovery
│   ├── layout.tsx
│   ├── manifesto
│   ├── page.tsx
│   ├── settings
│   └── symposium
├── _constants
│   └── server.ts
├── api
│   └── auth
├── dev
│   └── page.tsx
├── favicon.ico
├── fonts
│   ├── GeistMonoVF.woff
│   └── GeistVF.woff
├── global-error.tsx
├── globals.css
├── layout.tsx
├── lib
│   └── routes.ts
├── onboarding
│   ├── assignment1
│   ├── assignment2
│   ├── assignment3
│   ├── assignment4
│   ├── loading.tsx
│   └── welcome
└── page.tsx

The error message:

npx open-next build
Next.js version : 14.2.13
OpenNext v3.2.1

┌─────────────────────────────────┐
│ OpenNext — Building Next.js app │
└─────────────────────────────────┘

yarn run v1.22.19
$ next build
  ▲ Next.js 14.2.13
  - Environments: .env.local
  - Experiments (use with caution):
    · webpackBuildWorker
    · instrumentationHook

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (18/18)
   Finalizing page optimization  .   Collecting build traces 
 ✓ Collecting build traces    
 ⚠ Failed to copy traced files for /home/mover/lekondo-cotton/.next/server/app/(central)/page.js [Error: ENOENT: no such file or directory, copyfile '/home/mover/lekondo-cotton/.next/server/app/(central)/page_client-reference-manifest.js' -> '/home/mover/lekondo-cotton/.next/standalone/.next/server/app/(central)/page_client-reference-manifest.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'copyfile',
  path: '/home/mover/lekondo-cotton/.next/server/app/(central)/page_client-reference-manifest.js',
  dest: '/home/mover/lekondo-cotton/.next/standalone/.next/server/app/(central)/page_client-reference-manifest.js'
}
 ✓ Finalizing page optimization    

Route (app)                                        Size     First Load JS
┌ ƒ /                                              3.58 kB         249 kB
├ ○ /_not-found                                    1.03 kB         184 kB
├ ƒ /api/auth/[auth0]                              0 B                0 B
├ ƒ /api/auth/dev/dangerouslyGetAPIToken           0 B                0 B
├ ƒ /collection                                    1.15 kB         189 kB
├ ƒ /collection/[collectionId]                     8.8 kB          271 kB
├ ƒ /collection/[collectionId]/item/[itemId]       3.33 kB         228 kB
├ ƒ /collection/[collectionId]/item/[itemId]/edit  413 B           225 kB
├ ○ /dev                                           1.48 kB         189 kB
├ ƒ /discovery                                     322 B           183 kB
├ ƒ /manifesto                                     323 B           183 kB
├ ○ /onboarding/assignment1                        2.56 kB         221 kB
├ ○ /onboarding/assignment2                        2.7 kB          236 kB
├ ○ /onboarding/assignment3                        2.45 kB         263 kB
├ ○ /onboarding/assignment4                        3.53 kB         229 kB
├ ○ /onboarding/welcome                            673 B           191 kB
├ ƒ /settings                                      322 B           183 kB
├ ƒ /settings/privacy                              1.57 kB         197 kB
├ ƒ /settings/profile                              1.66 kB         213 kB
└ ƒ /symposium/[tag]                               5.95 kB         224 kB
+ First Load JS shared by all                      183 kB
  ├ chunks/52774a7f-acd6185c7912d037.js            36.1 kB
  ├ chunks/5347-99e5327102b28534.js                90.4 kB
  ├ chunks/fd9d1056-7ab42e1942c648c4.js            53.8 kB
  └ other shared chunks (total)                    2.53 kB

ƒ Middleware                                       160 kB

○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand

Done in 79.31s.

┌──────────────────────────────┐
│ OpenNext — Generating bundle │
└──────────────────────────────┘

Bundling middleware function...
Bundling static assets...
Bundling cache assets...
Building server function: default...
node:fs:2969
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, copyfile '/home/mover/lekondo-cotton/.next/standalone/.next/server/app/(central)/page_client-reference-manifest.js' -> '/home/mover/lekondo-cotton/.open-next/server-functions/default/.next/server/app/(central)/page_client-reference-manifest.js'
    at copyFileSync (node:fs:2969:3)
    at file:///home/mover/lekondo-cotton/node_modules/@opennextjs/aws/dist/build/copyTracedFiles.js:144:13
    at Map.forEach (<anonymous>)
    at copyTracedFiles (file:///home/mover/lekondo-cotton/node_modules/@opennextjs/aws/dist/build/copyTracedFiles.js:115:17)
    at generateBundle (file:///home/mover/lekondo-cotton/node_modules/@opennextjs/aws/dist/build/createServerBundle.js:108:11)
    at createServerBundle (file:///home/mover/lekondo-cotton/node_modules/@opennextjs/aws/dist/build/createServerBundle.js:69:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async build (file:///home/mover/lekondo-cotton/node_modules/@opennextjs/aws/dist/build.js:46:5)
    at async file:///home/mover/lekondo-cotton/node_modules/@opennextjs/aws/dist/index.js:9:1 {
  errno: -2,
  syscall: 'copyfile',
  code: 'ENOENT',
  path: '/home/mover/lekondo-cotton/.next/standalone/.next/server/app/(central)/page_client-reference-manifest.js',
  dest: '/home/mover/lekondo-cotton/.open-next/server-functions/default/.next/server/app/(central)/page_client-reference-manifest.js'
}

Node.js v18.18.0

next.config.mjs:

import { withSentryConfig } from '@sentry/nextjs';

/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**',
      },
      {
        protocol: 'http',
        hostname: '**',
      },
    ],
  },
};

// eslint-disable-next-line import/no-default-export
export default withSentryConfig(nextConfig, {
 // Sentry stuff
});

sst.config.ts:

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./.sst/platform/config.d.ts" />
export default $config({
  app(input) {
    return {
      name: 'lekondo-cotton',
      removal: input?.stage === 'prod' ? 'retain' : 'remove',
      home: 'aws',
      region: 'us-east-1',
      providers: {
        cloudflare: {
          version: '5.41.0',
          apiToken: process.env.CLOUDFLARE_API_TOKEN,
        },
      },
    };
  },
  async run() {
    new sst.aws.Nextjs('Lekondo', {
      domain: {
        name: process.env.DOMAIN,
        dns: sst.cloudflare.dns({
          zone: '123',
          override: true,
        }),
      },
      openNextVersion: '3.2.1',
      environment: {
        NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL ?? '',
        BASE_URL: process.env.BASE_URL ?? '',
        AUTH0_SECRET: process.env.AUTH0_SECRET ?? '',
        AUTH0_BASE_URL: process.env.AUTH0_BASE_URL ?? '',
        AUTH0_ISSUER_BASE_URL: process.env.AUTH0_ISSUER_BASE_URL ?? '',
        AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID ?? '',
        AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET ?? '',
        AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE ?? '',
      },
    });
  },
});
conico974 commented 2 weeks ago

Failed to copy traced files for /home/mover/lekondo-cotton/.next/server/app/(central)/page.js [Error: ENOENT: no such file or directory, copyfile '/home/mover/lekondo-cotton/.next/server/app/(central)/page_client-reference-manifest.js' -> '/home/mover/lekondo-cotton/.next/standalone/.next/server/app/(central)/page_client-reference-manifest.js']

This error indicates that something went wrong with next build itself, and since that's used by OpenNext to compute the server functions it explains the fail. You could try removing the .next folder

khuezy commented 2 weeks ago

When you move folders/filers around in next, you usually need to do a clean wipe of .next. There are some weird reference caching that can cause build issues.

moverware commented 2 weeks ago

@conico974 @khuezy next build goes off with out a hitch. I have cleared .next, .sst, etc. This also fails in my Github actions (that dont have a cache). But these are local logs currently.

 y build
Found '/home/mover/lekondo-cotton/.nvmrc' with version <18.18.0>
Now using node v18.18.0 (npm v9.8.1)
yarn run v1.22.19
$ next build
  ▲ Next.js 14.2.13
  - Environments: .env.local
  - Experiments (use with caution):
    · instrumentationHook

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (18/18)
   Finalizing page optimization  .   Collecting build trace
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (app)                                        Size     First Load JS
┌ ƒ /                                              3.58 kB         249 kB
├ ○ /_not-found                                    1.03 kB         184 kB
├ ƒ /api/auth/[auth0]                              0 B                0 B
├ ƒ /api/auth/dev/dangerouslyGetAPIToken           0 B                0 B
├ ƒ /collection                                    1.15 kB         189 kB
├ ƒ /collection/[collectionId]                     8.8 kB          271 kB
├ ƒ /collection/[collectionId]/item/[itemId]       3.33 kB         228 kB
├ ƒ /collection/[collectionId]/item/[itemId]/edit  413 B           225 kB
├ ○ /dev                                           1.48 kB         189 kB
├ ƒ /discovery                                     322 B           183 kB
├ ƒ /manifesto                                     323 B           183 kB
├ ○ /onboarding/assignment1                        2.56 kB         221 kB
├ ○ /onboarding/assignment2                        2.7 kB          236 kB
├ ○ /onboarding/assignment3                        2.45 kB         263 kB
├ ○ /onboarding/assignment4                        3.53 kB         229 kB
├ ○ /onboarding/welcome                            673 B           191 kB
├ ƒ /settings                                      322 B           183 kB
├ ƒ /settings/privacy                              1.57 kB         197 kB
├ ƒ /settings/profile                              1.66 kB         213 kB
└ ƒ /symposium/[tag]                               5.95 kB         224 kB
+ First Load JS shared by all                      183 kB
  ├ chunks/52774a7f-acd6185c7912d037.js            36.1 kB
  ├ chunks/5347-99e5327102b28534.js                90.4 kB
  ├ chunks/fd9d1056-7ab42e1942c648c4.js            53.8 kB
  └ other shared chunks (total)                    2.54 kB

ƒ Middleware                                       160 kB

○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand

Done in 75.21s.
conico974 commented 2 weeks ago

You're not running next build with ouput standalone, which is what OpenNext do and need. This part is failing, the error i showed you is not originating from OpenNext, but from Next itself

moverware commented 2 weeks ago

Is this standalone output? I don't have next globally installed or anything:

./node_modules/.bin/next build
  ▲ Next.js 14.2.13
  - Environments: .env.local
  - Experiments (use with caution):
    · instrumentationHook

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (18/18)
   Finalizing page optimization  .   Collecting build trace
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (app)                                        Size     First Load JS
┌ ƒ /                                              3.58 kB         249 kB
├ ○ /_not-found                                    1.03 kB         184 kB
├ ƒ /api/auth/[auth0]                              0 B                0 B
├ ƒ /api/auth/dev/dangerouslyGetAPIToken           0 B                0 B
├ ƒ /collection                                    1.15 kB         189 kB
├ ƒ /collection/[collectionId]                     8.8 kB          271 kB
├ ƒ /collection/[collectionId]/item/[itemId]       3.33 kB         228 kB
├ ƒ /collection/[collectionId]/item/[itemId]/edit  413 B           225 kB
├ ○ /dev                                           1.48 kB         189 kB
├ ƒ /discovery                                     322 B           183 kB
├ ƒ /manifesto                                     323 B           183 kB
├ ○ /onboarding/assignment1                        2.56 kB         221 kB
├ ○ /onboarding/assignment2                        2.7 kB          236 kB
├ ○ /onboarding/assignment3                        2.45 kB         263 kB
├ ○ /onboarding/assignment4                        3.53 kB         229 kB
├ ○ /onboarding/welcome                            673 B           191 kB
├ ƒ /settings                                      322 B           183 kB
├ ƒ /settings/privacy                              1.57 kB         197 kB
├ ƒ /settings/profile                              1.66 kB         213 kB
└ ƒ /symposium/[tag]                               5.95 kB         224 kB
+ First Load JS shared by all                      183 kB
  ├ chunks/52774a7f-acd6185c7912d037.js            36.1 kB
  ├ chunks/5347-99e5327102b28534.js                90.4 kB
  ├ chunks/fd9d1056-7ab42e1942c648c4.js            53.8 kB
  └ other shared chunks (total)                    2.53 kB

ƒ Middleware                                       160 kB

○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand
moverware commented 2 weeks ago

Looks to me like the error originates from the OpenNext — Generating bundle, after the build is successful. Is there a way for me to run this step via next directly?

conico974 commented 2 weeks ago

The first error which is the exact same btw is originating from next build image To run in standalone https://nextjs.org/docs/app/api-reference/next-config-js/output#automatically-copying-traced-files

moverware commented 2 weeks ago

Nice, same error in standalone mode. I'll open an issue with Next directly, thanks!

khuezy commented 2 weeks ago

Can you try upgrading your next version? I'm using groups too and haven't had issues building/copying groups.