sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.7k stars 111 forks source link

open next fails to build when used with the pages and app router #380

Open V01D-NULL opened 3 months ago

V01D-NULL commented 3 months ago

Codepipeline logs:

┌──────────────────────────────┐
--
76 | │ OpenNext — Generating bundle │
77 | └──────────────────────────────┘
78 |  
79 | Bundling static assets...
80 | node:fs:2969
81 | handleErrorFromBinding(ctx);
82 | ^
83 |  
84 | Error: ENOENT: no such file or directory, copyfile '/codebuild/output/src53762765/src/next/.next/BUILD_ID' -> '/codebuild/output/src53762765/src/next/.open-next/assets/BUILD_ID'
85 | at Object.copyFileSync (node:fs:2969:3)
86 | at createStaticAssets (file:///root/.npm/_npx/baabbad97c6af5a7/node_modules/open-next/dist/build.js:289:8)
87 | at build (file:///root/.npm/_npx/baabbad97c6af5a7/node_modules/open-next/dist/build.js:30:5) {
88 | errno: -2,
89 | syscall: 'copyfile',
90 | code: 'ENOENT',
91 | path: '/codebuild/output/src53762765/src/next/.next/BUILD_ID',
92 | dest: '/codebuild/output/src53762765/src/next/.open-next/assets/BUILD_ID'
93 | }
94 |  
95 | Node.js v18.18.2
96 | Error: Command failed: npx open-next@2.3.7 build
97 | at checkExecSyncError (node:child_process:890:11)
98 | at execSync (node:child_process:962:15)
99 | at NextjsBuild.build (/codebuild/output/src53762765/src/cdk/node_modules/cdk-nextjs-standalone/src/NextjsBuild.ts:151:13)
100 | at new NextjsBuild (/codebuild/output/src53762765/src/cdk/node_modules/cdk-nextjs-standalone/src/NextjsBuild.ts:116:14)
101 | at new Nextjs (/codebuild/output/src53762765/src/cdk/node_modules/cdk-nextjs-standalone/src/Nextjs.ts:156:22)
102 | at CoScheduleWebsiteStack.buildNextConstruct (/codebuild/output/src53762765/src/cdk/lib/cdk-stack.ts:32:20)
103 | at new CoScheduleWebsiteStack (/codebuild/output/src53762765/src/cdk/lib/cdk-stack.ts:26:10)
104 | at defineStack (/codebuild/output/src53762765/src/cdk/bin/cdk.ts:27:5) {
105 | status: 1,
106 | signal: null,
107 | output: [ null, null, null ],
108 | pid: 322,
109 | stdout: null,
110 | stderr: null
111 | }
112 |  
113 | Subprocess exited with error 1

I'm in the process of migrating our pages router to the new app router, all I changed was the bare minimum. New useRouter hooks in a global component, adding a layout.tsx, metadata, etc.

After doing that I've seen our builds fail on staging when running npx open-next@2.3.7 build. Building via next build works fine, so this is breaking somewhere in open-next.

Any ideas?

khuezy commented 3 months ago

Are you mixing cdk-nextjs-standalone with open-next? The output src folder looks sus: src53762765

V01D-NULL commented 3 months ago

Yes, actually. version ^4.0.0-beta.28

We use cdk-nextjs-standalone in our code and invoke open next in the buildCommand npx open-next@2.3.7 build

V01D-NULL commented 3 months ago

so quick update... buildCommand: 'npm run build && npx open-next@2.3.7 build' seems to work as a temporary fix Where the build script is just next build

Previously buildCommand was just npx open-next@2.3.7 build