Source maps allow Sonarly to show you the original source code location when errors occur, instead of minified code.
Step 1: Enable Sourcemap Generation
Add the sourcemap configuration to your build tool:
Vite
Next.js
Create React App
Nuxt 3
Vue CLI
Remix
SvelteKit
// vite.config.ts
export default defineConfig({
build: { sourcemap: 'hidden' }
})
// next.config.js
module.exports = {
productionBrowserSourceMaps: true
}
# In .env file
GENERATE_SOURCEMAP=true
// nuxt.config.ts
export default defineNuxtConfig({
sourcemap: { client: true }
})
// vue.config.js
module.exports = {
productionSourceMap: true
}
Sourcemaps are enabled by default in Remix.
// svelte.config.js
const config = {
kit: { vite: { build: { sourcemap: 'hidden' } } }
}
Step 2: Add Sourcemap Uploader to Build Script
Add the sourcemap uploader to your package.json build script. Use the correct folder path for your framework:
| Framework | Config file to detect | Sourcemap folder |
|---|
| Vite | vite.config.ts or vite.config.js | ./dist/assets/ |
| Next.js | next.config.js or next.config.mjs | ./.next/static/chunks/ |
| Create React App | react-scripts in package.json | ./build/static/js/ |
| Nuxt 3 | nuxt.config.ts | ./.output/public/_nuxt/ |
| Vue CLI | @vue/cli-service in package.json | ./dist/js/ |
| Remix | remix.config.js | ./public/build/ |
| SvelteKit | svelte.config.js | ./build/_app/immutable/ |
Build Script Examples
Vite
Next.js
Create React App
Nuxt 3
Vue CLI
Remix
SvelteKit
{
"scripts": {
"build": "vite build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./dist/assets/ || true"
}
}
{
"scripts": {
"build": "next build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./.next/static/chunks/ || true"
}
}
{
"scripts": {
"build": "react-scripts build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./build/static/js/ || true"
}
}
{
"scripts": {
"build": "nuxt build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./.output/public/_nuxt/ || true"
}
}
{
"scripts": {
"build": "vue-cli-service build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./dist/js/ || true"
}
}
{
"scripts": {
"build": "remix build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./public/build/ || true"
}
}
{
"scripts": {
"build": "vite build && npx @sonarly/sourcemap-uploader --api-key=YOUR_PROJECT_KEY ./build/_app/immutable/ || true"
}
}
The || true at the end ensures your build doesn’t fail if the sourcemap upload fails (e.g., network issues).
Verify
After deploying, check that:
.map files are generated in your build folder
- Upload command shows success (no 404 errors)
- Errors in your Sonarly dashboard show original source code locations
Configure backend traces
Link backend errors to frontend sessions