Top-level import

Learn about how the Nuxt SDK adds a top-level import to the build output.

Sentry needs to be initialized before the application starts. If the default way of adding an --import CLI flag flag does not work for you, set up the SDK for adding a top-level import. This will import the Sentry server-side config at the top of the Nuxt server entry file. In this case, Sentry isn’t initialized before the app starts, but is set up as early as possible.

Enable the top-level import by setting autoInjectServerSentry:

nuxt.config.ts
Copied
export default defineNuxtConfig({
  sentry: {
    autoInjectServerSentry: "top-level-import",
  },
});

By default, the SDK will add the Sentry server config to the build output (typically, .output/server/sentry.server.config.mjs).

With the top-level import, the Nuxt server entry file will look something like this:

.output/server/index.mjs
Copied
import "./sentry.server.config.mjs";
// Note: The file may have some imports and code, related to debug IDs
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").