Next.js prod build logs errors twice
Link to the code that reproduces this issue
https://github.com/kkoudelka/error-repro-app
To Reproduce
- Build the app
yarn build - Start the app
yarn start - Navigate to
/
Current vs. Expected behavior
Since the page throws an error, I expected the error to be logged once. However, it is logged twice.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 32510
Available CPU cores: 28
Binaries:
Node: 20.14.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 15.0.0-canary.49 // Latest available version is detected (15.0.0-canary.49).
eslint-config-next: N/A
react: 19.0.0-rc-6f23540c7d-20240528
react-dom: 19.0.0-rc-6f23540c7d-20240528
typescript: 5.3.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Runtime
Which stage(s) are affected? (Select all that apply)
next start (local), Vercel (Deployed), Other (Deployed)
Additional context
Hi, I've stumbled upon issue started when I wanted to log errors using pino logger. I patched the /dist/build/output/log.js in next with yarn patch next and replaced console with pino.
This has worked quite well locally, starting the server would print the Starting and Ready in xxx messages in JSON, however any thrown error would print both JSON and normal log (probably using console.log?).
I decided to investigate further and created a new project using the reproduction example. After starting this app and navigating to /, the error is logged twice. I have no idea why. Is this a bug (and if not, can I patch this different file to use pino instead)?
▲ Next.js 15.0.0-canary.49
- Local: http://localhost:3000
✓ Starting...
✓ Ready in 221ms
Error: Sample error
at n (E:\Projects\error-repro-app\.next\server\app\page.js:1:2359)
at i (E:\Projects\error-repro-app\.next\server\app\page.js:1:2414)
at ey (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:11982)
at e (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:15521)
at eP (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:16004)
at Array.toJSON (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:13431)
at stringify (<anonymous>)
at eI (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:23817)
at eN (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:24035)
at eL (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:24443) {
digest: '63053212'
}
Error: Sample error
at n (E:\Projects\error-repro-app\.next\server\app\page.js:1:2359)
at i (E:\Projects\error-repro-app\.next\server\app\page.js:1:2414)
at ey (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:11982)
at e (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:15521)
at eP (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:16004)
at Array.toJSON (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:13431)
at stringify (<anonymous>)
at eI (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:23817)
at eN (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:24035)
at eL (E:\Projects\error-repro-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:84:24443) {
digest: '63053212'
}
We currently don't support swapping the default logger, especially using patches. These types of modifications cannot be considered stable unfortunately.
Hey @wyattjoh, I understand, however could you point me in the right direction? I have no idea why the error is logged twice (even without patching the internal logger; this can be observed in the reproduction app).
If the error is printing twice, even with our current logger, then it's likely that it's related to some internal management of that error is incorrect. We're working to improve the DX for Next.js, and realize that this may be an issue. I'm going to re-open this issue to track attempting to resolve the double printing, but we're likely not to support additional loggers at this time.
FYI I'm seeing this issue on Next.JS version 14.2.4 as well. Both in the development server and the prod build.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.