All guidesMore providers: databases, auth, hosting, email and payments
On this page

Angular error

Angular

NG0507: HTML content was altered after server-side rendering

By Ohad Krispin, founder of VibeRaven · LinkedIn

"NG0507: HTML content was altered after server-side rendering" means Angular hydration, running in the browser, did not find the nghm comment that the server puts at the start of the body, so bootstrapApplication fails with NG0507 and hydration does not run. The Angular error page names two causes: a CDN feature that removes whitespace and comment nodes from HTML, and a build step that post-processes the server-rendered HTML. Turn that option off for the HTML, redeploy, and check that the page you fetch still contains the nghm comment. A production build prints only "NG0507", without the long text. Reproduced with @angular/core 21.2.25 on 2026-10-31.

How do I check that the nghm comment reaches the browser?

The server adds a comment node with the text nghm as the first child of the body (platform-server, utils.ts), and the client looks for it before it hydrates. Fetch your page as the browser gets it and look for the comment. If it is missing, something between Angular's server render and the browser removed it.

curl -s https://your-app.example.com/ | grep -o "<!--nghm-->"

Why does it appear only in production, and with no message?

A local dev server usually has no CDN or HTML optimizer in front of it. The Angular issue that added this check says some CDNs remove all comment nodes and spaces from HTML, which makes an app work in development and fail in production. In the source (core/src/hydration/utils.ts), the sentence that explains the error is included only when ngDevMode is on. In a local run with ngDevMode set to false, the error message was only NG0507; look the code up on the Angular error page.

bootstrap failed: NG0507

Is NG0507 the same as NG0505?

No. The Angular page for NG0505, "No hydration info in server response", says the server response has no serialized data, often because provideClientHydration() is missing from the server configuration. With NG0507 the server did its work, and the marker comment was removed on the way to the browser.

Checklist

How to fix it, then check the fix

  1. 01
    Fetch the page the way a browser does and look for the marker:
    curl -s https://your-app.example.com/ | grep -c "nghm"
  2. 02If the marker is missing, request the same page from the origin, without the CDN or proxy in front of it, and compare. The layer that drops the comment is the one to change.
  3. 03In the CDN or proxy configuration, look for an option that removes whitespace or comments from HTML, and turn it off for your HTML pages, as the Angular error page says.
  4. 04If a script in your build or deploy changes the server-rendered HTML, such as an HTML minifier, exclude those files or make it keep comment nodes and whitespace.
  5. 05Redeploy, load the page, and check that NG0507 is gone from the browser console.

Related

Sources

Official docs behind this checklist

FAQ

FAQ for builders before launch

Does Vercel, Netlify or Firebase Hosting remove the comment?

The Angular docs do not name a host. They say some CDN providers have a built-in feature to remove whitespace and comment nodes from HTML. This page did not test any host, so check every CDN, proxy or HTML optimizer in front of your app, then your own build steps.

Does the error stop the app?

In the local run, bootstrapApplication rejected with NG0507, so the client app did not start in that run.

Do whitespace changes matter as much as removed comments?

The Angular error page says hydration needs the SSR output to stay intact, including whitespace and comment nodes, and that both must be retained in the generated HTML. The check that raises NG0507 looks for the nghm comment only.