---
title: "Dynamic Import (experimental)"
description: "Learn about how the Nuxt SDK leverages dynamic input() in the build output."
url: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/dynamic-import/
---

# Dynamic Import (experimental) | Sentry for Nuxt

## [Understanding the `import()` expression](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/dynamic-import.md#understanding-the-import-expression)

This installation method doesn't work with more recent versions of Nuxt/Nitro.

We recommend reading the guide for installing the SDK with the [CLI flag `--import`](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cli-import.md) or [limited server tracing](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/limited-server-tracing.md)

The `import()` expression, or dynamic import, enables flexible, conditional module loading in ESM. Node.js will generate a separate module graph for any code wrapped in a dynamic `import()`. This separate graph is evaluated **after** all modules, which are statically `import`ed.

By using the Sentry Nuxt SDK, the server-side application will be wrapped in a dynamic `import()`, while the Sentry configuration will be imported with a static `import`. This makes it possible to initialize the Sentry Nuxt SDK at startup, while the Nitro server runtime loads later because it is `import()`ed. This early initialization of Sentry is required to correctly set up the SDK's instrumentation of various libraries.

## [Scenarios where `import()` doesn't work](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/dynamic-import.md#scenarios-where-import-doesnt-work)

Depending on your setup and which version of Nitro is used, the server-side is sometimes not correctly initialized. The build output **must not** include a regular `import` of the Nitro runtime (e.g. `import './chunks/nitro/nitro.mjs'`). See the ([GitHub issue here](https://github.com/getsentry/sentry-javascript/issues/14514)) for more information.

As a temporary workaround, you can add the following overrides in your application:

`package.json`

```json
"overrides": {
  "nitropack": "~2.9.7",
  "@vercel/nft": "^0.27.4"
}
```

You can also check out the guide for installing the SDK with the [CLI flag `--import`](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cli-import.md) or [limited-server-tracing](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/limited-server-tracing.md).

## [Initializing Sentry with Dynamic `import()`](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/dynamic-import.md#initializing-sentry-with-dynamic-import)

Enable the dynamic `import()` by setting `autoInjectServerSentry`:

`nuxt.config.ts`

```typescript
export default defineNuxtConfig({
  sentry: {

    autoInjectServerSentry: "experimental_dynamic-import",

  },
});
```

After setting this, the Sentry Nuxt SDK will add build-time configuration so that your app will be wrapped with `import()`, ensuring that Sentry can be initialized before any other modules.

The Nuxt server entry file will look something like this:

`.output/server/index.mjs`

```javascript
// Note: The file may have some imports and code, related to debug IDs
Sentry.init({
  dsn: "...",
});

import("./chunks/nitro/nitro.mjs").then(function (n) {
  return n.r;
});
```

## [Re-exporting serverless handler functions](https://docs.sentry.io/platforms/javascript/guides/nuxt/install/dynamic-import.md#re-exporting-serverless-handler-functions)

Sentry automatically detects serverless handler functions in the build output and re-exports them from the server entry file.

By default, Sentry re-exports functions named `handler`, `server`, and `default` exports. This will work in most cases and no other action is required. If your serverless function has a custom name, you can override it with `experimental_entrypointWrappedFunctions`:

`nuxt.config.ts`

```javascript
export default defineNuxtConfig({
  modules: ["@sentry/nuxt/module"],

  sentry: {
    // Customize detected function names
    // Default value: ['default', 'handler', 'server']

    experimental_entrypointWrappedFunctions: ["customFunctionName"],

  },
});
```
