Next.js: Hide .js.map Source Maps in Production
Updated 2026-10-26
A public source map turns your minified Next.js chunks back into readable source, often with comments and original file names. Next.js does not ship browser source maps by default, so if yours are public, something in your config turned them on. Here is how to find out and fix it.
Check whether maps are public
Open any chunk under /_next/static/chunks/ and look at its last line. A //# sourceMappingURL=...map comment means a map is referenced. Then request the .map URL directly: a 200 with JSON containing "sources" (and often "sourcesContent") means it is public. A free ShipGuard scan checks this passively for every same-site script it finds.
curl -s https://your-app.com/ | grep -o '/_next/static/chunks/[^"]*\.js' | head -3
curl -sI https://your-app.com/_next/static/chunks/<chunk>.js.map | head -1Turn them off
Look for productionBrowserSourceMaps: true in next.config.js / next.config.ts and remove it (the default is off). Also look for custom webpack config that sets devtool for client builds.
// next.config.ts
import type { NextConfig } from "next";
const config: NextConfig = {
productionBrowserSourceMaps: false, // default; remove any override
};
export default config;Keep readable stack traces without publishing maps
If you enabled maps for error tracking, upload them privately during the build and delete them from the output before it is deployed. Error-tracking SDKs such as Sentry's Next.js plugin can upload maps and delete them after upload; check the option name for your SDK version. If you build maps yourself, removing them after the upload step works on any host:
{
"scripts": {
"build": "next build && node scripts/upload-maps.mjs && find .next/static -name '*.map' -delete"
}
}What maps do and do not reveal
Maps reveal client code only: the same code a determined person could read from the minified bundle, but much faster and with comments. They do not expose server components' source, API route code or environment variables that were never sent to the browser. The real risk is what your client code contains: hard-coded keys, hidden admin routes, or internal endpoint names.
Checklist
productionBrowserSourceMapsis not set to true- No custom client
devtooloverride in webpack config - Chunks have no sourceMappingURL comment (or the .map URL returns 404)
- Maps uploaded privately to the error tracker if needed, then deleted from the build
- No secrets or hidden admin URLs in client code (maps or not)
Copy-paste fix prompt
Make sure this Next.js app does not serve public browser source maps in production: remove productionBrowserSourceMaps or any client devtool override, keep private source map upload for the error tracker if it is configured (deleting the .map files after upload), and add a post-build check that fails if any .map file remains in .next/static.FAQ
Does hiding source maps make my app secure?
No. It removes an easy way to read your code. Anything shipped to the browser is still public, so secrets must never be in client code.
Are server-side source maps public on Vercel?
Server build output is not served as static files. The public risk is browser maps under /_next/static.
Is a public source map a vulnerability?
It is information disclosure. How serious it is depends on what the code reveals.
Check your deployed app in seconds
Free passive scan: leaked keys, Supabase exposure, public config files and headers.
Run a free scan