Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs Coming soon
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare Laravel Laravel PHP PHP JavaScript JavaScript React React Vue Vue Svelte Svelte Protocol Protocol
  • General
  • Installation
  • Resolving bundled code
  • API reference
  • Errors
  • Reporting errors
  • Client hooks
  • Data Collection
  • Adding custom context
  • Adding glows

Resolving bundled code

When you bundle your frontend code for production (using Webpack, Vite, Gulp, Babel…), it will get minified and transformed and ultimately won't look like the original code any more. This causes the code snippets attached to error reports to be malformed as well. The solution to this problem is uploading a sourcemap.

Using one of our plugins, you can automatically upload the sourcemaps produced by your bundler. We'll then use them to format your error reports to show a clean stacktrace that resembles your original code.

The following options are available:

  • Vite
  • Webpack
  • Laravel Mix (using Webpack plugin)
  • Manually uploading sourcemaps

Vite

When using Vite (v5, v6, v7, or v8) to build your front-end code, you can use Flare's Vite plugin.

To get started, run one of the following commands to install the plugin:

npm install @flareapp/vite
# or
yarn add @flareapp/vite
# or
pnpm add @flareapp/vite

Next, add the plugin to your vite.config.js file and fill in your Flare project's public key:

import { defineConfig } from 'vite';
import flareSourcemapUploader from '@flareapp/vite';

export default defineConfig({
    plugins: [
        flareSourcemapUploader({
            key: 'YOUR PROJECT KEY HERE'
        }),
    ],
});

Finally, run the vite build command to confirm that sourcemaps are generated. You should see the following lines in the output:

@flareapp/vite: Uploading 12 sourcemap files to Flare.
@flareapp/vite: Successfully uploaded sourcemaps to Flare.

Integration notes

  • The plugin also passes your project's API token to the JavaScript client by setting a global variable. This way, when initializing the Flare JS client, you can just run flare.light() without having to pass in your API key.
  • The plugin automatically enables hidden sourcemaps in your Vite build configuration when uploading is active. You don't need to set build.sourcemap yourself — it's handled for you. If you've already set a custom sourcemap option, the plugin will respect it.
  • By default, the plugin will not upload your sourcemaps to Flare when compiling in Vite's development mode. You can override this behaviour using the runInDevelopment option.
  • You can skip sourcemap uploads entirely by setting the SKIP_SOURCEMAPS=true environment variable.

Vite plugin options

Option Description
key (required): your Flare project's public API key
base the base path of built output (defaults to Vite's base path)
apiEndpoint the endpoint for uploading sourcemaps (defaults to 'https://flareapp.io/api/sourcemaps')
runInDevelopment whether to upload sourcemaps when NODE_ENV=development or when running the dev server (defaults to false)
version the sourcemap version (defaults to a fresh uuid per build)
removeSourcemaps whether to remove the sourcemaps after uploading them (defaults to false). Comes in handy when you want to upload sourcemaps to Flare but don't want them published in your build.

Webpack or Laravel Mix

If you're using Laravel Mix or Webpack (v3, v4 or v5), you can use our Webpack plugin.

To get started, run one of the following commands to install the plugin:

npm install @flareapp/flare-webpack-plugin-sourcemap --dev
# or
yarn add @flareapp/flare-webpack-plugin-sourcemap --dev
# or
pnpm add @flareapp/flare-webpack-plugin-sourcemap --dev

Next, modify your webpack.config.js or webpack.mix.js file to enable sourcemaps and the plugin. You can find example configurations for Laravel Mix and Webpack below. The configuration must only be added to one of these configuration files, otherwise it may lead to unexpected behaviour.

The only required parameter for the plugin is a configuration object with a key property. Enter your Flare project's public key here.

The plugin also passes your project's API token to the JavaScript client by setting a global variable. This way, when initializing the Flare JS client, you can just run flare.light() without passing in your API key.

By default, the plugin will not upload your sourcemaps to Flare when compiling in Webpack's development or watch modes. You can override this behaviour using the runInDevelopment option.

Laravel Mix

In a Laravel Mix build, you can also use the aforementioned Webpack plugin. Follow the steps above to install it. Then, add the following to your webpack.mix.js file:

const FlareWebpackPluginSourcemap = require("@flareapp/flare-webpack-plugin-sourcemap");

mix
    // ...
    .webpackConfig({
        plugins: [ new FlareWebpackPluginSourcemap({ key: "your-project-key" }) ],
    })
    .sourceMaps(true, 'hidden-source-map');

The configuration is the same as for the Webpack plugin.

Webpack

webpack.config.js

const FlareWebpackPluginSourcemap = require("@flareapp/flare-webpack-plugin-sourcemap");

module.exports = {
    // ...
    plugins: [ new FlareWebpackPluginSourcemap({ key: "your-project-key" }) ],
    devtool: "hidden-source-map",
};

Webpack plugin options

You can pass some options to the plugin, in the same object as the key:

Option Default Description
key empty (required) This is your project's public token. The plugin will automatically pass it to the Flare client through a global variable.
runInDevelopment false Setting this value to true will cause the plugin to upload your sourcemaps even when compiling in webpack's dev mode. This will still prevent the plugin from uploading sourcemaps when compiling in watch mode.
versionId empty The plugin generates a random ID for each build, so that Flare knows which incoming reports are linked to which sourcemaps. Using this config option, you can set an ID you decide for yourself e.g. when deploying your code on multiple servers. Make sure it's different for each build.
removeSourcemaps false If you'd rather not deploy your sourcemaps to your production environment, you can add removeSourcemaps: true to remove them before the build completes.
debug false If your bundler is running into issues while uploading the sourcemaps to Flare, set debug: true to get more verbose output.

Manually uploading sourcemaps

We don't have any UI in the Flare dashboard for uploading your sourcemaps. You can, however, upload the sourcemap manually or with a custom script that runs after building your assets.

Send a POST request to https://flareapp.io/api/sourcemaps with the following JSON payload:

{
    "key": "your-project-key",
    "version_id": "versionId",
    "relative_filename": "/js/app.js",
    "sourcemap": "base64 string of gzipped sourcemap (this sounds more complicated than it is)"
}
Key Description
key The public API key of your project in Flare.
version_id This has to be a project-unique string that is also included in your bundled code as a global environment variable FLARE_SOURCEMAP_VERSION. Alternatively, you can set the sourcemapVersionId property via flare.configure({ sourcemapVersionId: 'your-version' }). In the webpack plugin, we use the uuid4 spec to generate a unique string for each build.
relative_filename The relative path to the file this sourcemap belongs to, starting from the root of your domain.
sourcemap A base64 string of your gzipped sourcemap.

Here's how you could generate it using the built-in Zlib library for Node.js, but the commandline gzip tool should work just as well:

const zlib = require('zlib');

const base64GzipSourcemap = zlib.deflateRawSync(sourcemap.content).toString('base64');
Installation API reference
  • On this page
  • Vite
  • Webpack or Laravel Mix
  • Manually uploading sourcemaps

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by
Flare