Build hangs indefinitely at the end
Answered
Tamás Soós posted this in #help-forum
Hi. I'm using next@14.2.13 with npm@10.8.2, when I run
Then it just hangs. I have no idea what it's still doing.
I'm running this on my home Ubuntu server 24.04.1 LTS with node v20.17.0 installed via nvm.
I've tried the following:
- Cleared npm cache via
- Removed
- Reinstalled dependencies
This is the example app created by create-next-app@latest
Running
Executing
When I clone the same repo on my laptop the build works fine. It must be something with my server, any ideas?
npm run build I get the following:home-web-app@0.1.0 build
next build
▲ Next.js 14.2.13
Creating an optimized production build ...
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
✓ Generating static pages (5/5)
✓ Collecting build traces
✓ Finalizing page optimization
Route (app) Size First Load JS
┌ ○ / 5.25 kB 92.3 kB
└ ○ /_not-found 871 B 88 kB
+ First Load JS shared by all 87.1 kB
├ chunks/23-78802c962dc3836c.js 31.6 kB
├ chunks/fd9d1056-2821b0f0cabcd8bd.js 53.6 kB
└ other shared chunks (total) 1.86 kB
○ (Static) prerendered as static contentThen it just hangs. I have no idea what it's still doing.
I'm running this on my home Ubuntu server 24.04.1 LTS with node v20.17.0 installed via nvm.
I've tried the following:
- Cleared npm cache via
npm cache clean --force- Removed
.next/ node_modules/ package-lock.json- Reinstalled dependencies
This is the example app created by create-next-app@latest
Running
npm run dev works fine.Executing
npm run start after canceling the build seems to be starting up the server just fine. It displays the example page just fine. When I clone the same repo on my laptop the build works fine. It must be something with my server, any ideas?
Answered by Tamás Soós
Anyway, I opened an issue on github. If anyone else's build just hangs, try disabling the telemetry module.
46 Replies
Is it just your terminal hanging? Hit enter after it starts to hang, if your sshing into it ive seen putty have hangups 'finishing'
Your getting the totality of all the responses, just not 'appearing' as though its finished in the terminal
based on what you provided
Tried pressing Enter it doesn't help. I also tried to run the build directly on the machine without SSH and the same thing happens. To be honest I think I'll downgrade to Ubuntu 22.04.5 unless I can get more info about what could be wrong.
And I'm getting the same on Ubuntu 22.04.5 😅
Updated to next@14.2.14, but same issue.
I def dont think its a nextjs issue tbh
but Idk what suggestions I can give you :/
Yeah it's really weird. Is there a way to see the build logs with as much detail as possible?
I think there is a debug switch?
Yeah there is
Right I was thinking a lot more detailed. I also tried using some of the other build flags and I can get it to hang after the Dynamic line too.
next build -d --experimental-app-only --no-mangling --no-lint --experimental-build-mode compile
⚠ Linting is disabled.
⚠ Mangling is disabled. Note: This may affect performance and should only be used for debugging purposes.
▲ Next.js 14.2.14
Creating an optimized production build ...
✓ Compiled successfully
✓ Collecting page data
✓ Collecting build traces
✓ Finalizing page optimization
Redirects
┌ source: /:path+/
├ destination: /:path+
└ permanent: true
Route (app) Size First Load JS
┌ ƒ /
└ ƒ /_not-found
+ First Load JS shared by all 87.1 kB
├ chunks/117-010f5c67a96d64ec.js 31.6 kB
├ chunks/fd9d1056-aa94ea5c2eabf904.js 53.6 kB
└ other shared chunks (total) 1.86 kB
ƒ (Dynamic) server-rendered on demand@Jboncz
I've tested creating a new app using create-next-app directly on the server. Same result.
Yeah like I said before this isnt a nextjs issue, your looking in the wrong spot.
@gin can u try with a different package manager?
Tried with yarn, same result.
@Jboncz Yeah like I said before this isnt a nextjs issue, your looking in the wrong spot.
The build script is my only starting point. Where else would you suggest to look?
Also tried with node 18, same result.
@Tamás Soós Tried with yarn, same result.
try with bun
@gin try with bun
Same result. Did a :
bun run next buildOf course removed
node_modules and package-lock and .next before.It's something in the build script for sure, but the underlying reason has to do with my setup.
I'm using nvm. Tried with 18, 20 and 22
and yes now on ubuntu server 22 LTS
ah so basically its a vps or something?
It's my homelab. I'm logged into it locally
can u check your cpu usage when running build?
with htop or btop or something
and if u say
now u could try switching the distro to a more robust one like debianCPU goes up while compiling then goes back to pretty much zero after it gets stuck. Memory usage is steady
I'd like to keep trying a little longer before I switch distros. I've already downgraded from Ubuntu 24 to 22
Alright going to the source it is then. I found the line that's hanging:
I can see
rewrites,
headers
}));
}
await nextBuildSpan.traceChild("print-tree-view").traceAsyncFn(()=>(0, _utils1.printTreeView)(pageKeys, pageInfos, {
distPath: distDir,
buildId: buildId,
pagesDir,
useStaticPages404,
pageExtensions: config.pageExtensions,
appBuildManifest,
buildManifest,
middlewareManifest,
gzipSize: config.experimental.gzipSize
}));
console.log("Before telemetry-flush");
await nextBuildSpan.traceChild("telemetry-flush").traceAsyncFn(()=>telemetry.flush());
console.log("After telemetry-flush");
});
} finally{
// Ensure we wait for lockfile patching if present
await _swc.lockfilePatchPromise.cur;
// Ensure all traces are flushed before finishing the command
await (0, _trace.flushAllTraces)();
(0, _swc.teardownTraceSubscriber)();
(0, _swc.teardownHeapProfiler)();
}
}I can see
Before telemetry-flush, but After telemetry-flush never gets printed.Wow and setting
export NEXT_TELEMETRY_DISABLED=1 makes the issue go away!Now the question is what's going wrong in that flush.
Some of the calls to the telemetry POST endpoint hang indefinitely. After adding a manual 5 sec timeout I get:
Aborted: [
{
eventName: 'NEXT_BUILD_COMPLETED',
payload: {
durationInSeconds: 0,
totalAppPagesCount: 3,
totalPageCount: 0,
hasDunderPages: false,
hasTestPages: false
}
}
]
Aborted: [
{
eventName: 'NEXT_LINT_CHECK_COMPLETED',
payload: {
durationInSeconds: 0,
eslintVersion: '8.57.1',
lintedFilesCount: 2,
lintFix: false,
nextEslintPluginVersion: '14.2.13',
nextEslintPluginErrorsCount: 0,
nextEslintPluginWarningsCount: 0,
nextRulesEnabled: [Object],
buildLint: true
}
}
]
Aborted: [
{
eventName: 'NEXT_TYPE_CHECK_COMPLETED',
payload: {
durationInSeconds: 0,
typescriptVersion: '5.6.2',
inputFilesCount: 6,
totalFilesCount: 428,
incremental: true
}
}
]
Aborted: [
{
eventName: 'NEXT_BUILD_FEATURE_USAGE',
payload: { featureName: 'experimental/optimizeCss', invocationCount: 0 }
},
{
eventName: 'NEXT_BUILD_FEATURE_USAGE',
payload: {
featureName: 'experimental/nextScriptWorkers',
invocationCount: 0
}
},
{
eventName: 'NEXT_BUILD_FEATURE_USAGE',
payload: { featureName: 'optimizeFonts', invocationCount: 1 }
},
{
eventName: 'NEXT_BUILD_FEATURE_USAGE',
payload: { featureName: 'experimental/ppr', invocationCount: 0 }
}
]Anyway, I opened an issue on github. If anyone else's build just hangs, try disabling the telemetry module.
Answer