Compatability with Next.js

Resolved 💬 3 comments Opened Aug 24, 2025 by gaojude Closed Nov 27, 2025
💡 Likely answer: A maintainer (bolinfest, collaborator) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.23.0

Which model were you using?

gpt-5

What platform is your computer?

Darwin 25.0.0 arm64 arm

What steps can reproduce the bug?

Open Codex CLI at any Next.js project and say "build the project".

What is the expected behavior?

The script should take less than 10 seconds to complete:

> time pnpm build

...
pnpm build  0.66s user 0.19s system 12% cpu 6.574 total

What do you see instead?

Then it runs the build script from package manager, but that takes forever:

user
run bulid and fix the error from it

codex
Running pnpm build to catch errors and fix them.

⚙︎ Working • 263s
  └ ⌨️ pnpm build

<img width="927" height="494" alt="Image" src="https://github.com/user-attachments/assets/c2e2c262-9f23-40ca-904e-da31a31f50ff" />

Additional information

_No response_

View original on GitHub ↗

3 Comments

gaojude · 1 year ago

https://github.com/gaojude/dio-build-fail

When running turbopack build in Codex sandbox, we've seen it running forever, or throwing the following error:

>_ You are using OpenAI Codex in ~/code/dio-build-fail

 To get started, describe a task or try one of these commands:

 /init - create an AGENTS.md file with instructions for Codex
 /status - show current session configuration and token usage
 /diff - show git diff (including untracked files)

user
run pnpm build

codex
Kicking off the build to see current errors.

✗ Failed (exit -1)
  └ ⌨️ pnpm build
    
    -----
    FATAL: An unexpected Turbopack error occurred. A panic log has been written to /var/folders/
r4/vnhg7wkn0dx2zsmxccrd6rg00000gn/T/next-panic-4c9e3ba8715018ecd69e400acc83c3da.log.
    
    To help make Turbopack better, report this error by 
… +47 lines
        at ignore-listed frames {
      errno: -1,
      code: 'EPERM',
      syscall: 'kill'
    }

codex
Build failed due to Turbopack port binding; inspecting package.json scripts.

✓ Completed
  └ ⌨️ cat -n package.json | sed -n '1,200p'

🖐 Turn interrupted

Whereas, running it outside Codex execution would result in a proper compilation error.

Token usage: total=2751 input=2256 (+ 10880 cached) output=495 (reasoning 384)
❯ pnpm build

> dio-build-fail@0.1.0 build /Users/jude/code/dio-build-fail
> next build --turbopack

   ▲ Next.js 15.5.1-canary.6 (Turbopack)
   - Experiments (use with caution):
     ✓ cacheComponents
     ✓ enablePrerenderSourceMaps (enabled by `experimental.cacheComponents`)

   Creating an optimized production build ...
 ✓ Finished writing to disk in 17ms

> Build error occurred
Error: Turbopack build failed with 1 errors:
./app/page.tsx:3:14
Ecmascript file had an error
  1 | import Image from "next/image";
  2 |
> 3 | export const dynamic = "force-dynamic";
    |              ^^^^^^^
  4 |
  5 | export default function Home() {
  6 |   return (

Route segment config "dynamic" is not compatible with `nextConfig.experimental.cacheComponents`. Please remove it.


    at <unknown> (./app/page.tsx:3:14)
gaojude · 1 year ago

A separate issue:

If you remove --turbopack from build script.

diff --git a/package.json b/package.json
index 6a7279c..2fcc303 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
   "private": true,
   "scripts": {
     "dev": "next dev --turbopack",
-    "build": "next build --turbopack",
+    "build": "next build",
     "start": "next start"
   },
   "dependencies": {

The build would fail due to the sandbox's network restriction. During build, Next.js build process needs to download fonts; preventing it from network access would result in build failure.

user
run pnpm build

codex
Running the build script to verify the current state.

✗ Failed (exit -1)
  └ ⌨️ pnpm build
    getaddrinfo ENOTFOUND fonts.googleapis.com
    
    Retrying 1/3...
    getaddrinfo ENOTFOUND fonts.googleapis.com
    
… +55 lines
        at ignore-listed frames {
      errno: -1,
      code: 'EPERM',
      syscall: 'kill'
    }
bolinfest collaborator · 1 year ago

These commands need to get renamed, but to investigate what happens when a command runs in the sandbox provided by Codex, I would try:

# Run `pnpm build` in a sandbox that can read all files on disk, but cannot write files or access network.
codex debug seatbelt -- pnpm build
# Run`pnpm build` in a sandbox that can write to cwd, but still cannot access the network.
codex debug seatbelt --full-auto -- pnpm build

Indeed, lack of network access appears to be an issue, since we see:

Build failed due to Turbopack port binding

You can use --dangerously-bypass-approvals-and-sandbox to disable the sandbox, but we do not currently have support for customizing the network policy for the sandbox.

The other option today is to run Codex in a Docker container with --dangerously-bypass-approvals-and-sandbox, but to use Docker's options for configuring the network policy for the container.