Skip to content

[Nuxt] Improve tracing functionality in ESM #13943

Closed
@s1gr1d

Description

@s1gr1d

Description

Problem Statement

Currently, you have to add the Sentry server config from the build output to the --input parameter of your node script like this:

node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs

The --import CLI flag makes it possible to preload a module. The server config file needs to be added with the --import flag as Sentry needs to be loaded before other modules to register a hook internally:

moduleModule.register('import-in-the-middle/hook.mjs', importMetaUrl, getRegisterOptions(esmHookConfig));

However, this needs extra configuration from the user-side and it makes the deployment setup more complicated (as different deployment providers have a different feature set and most don't fully support modification of the node run script).

Solution

The internally discussed idea is to wrap the server entry file with a dynamic import (import()), as this also runs the code after everything else (see here).

This would change the output from this:

server/
|-- index.mjs (server entry with "import './chunk/runtime.mjs'")
|-- sentry.server.config.mjs (sentry config)
|-- chunk/
|   |-- runtime.mjs (server runtime)

to this:

server/
|-- index.mjs (server entry with "import('./chunk/runtime.mjs')" and "import './sentry.server.config.mjs'")
|-- sentry.server.config.mjs (sentry config)
|-- chunk/
|   |-- runtime.mjs (server runtime)

Tasks

Metadata

Metadata

Assignees

Labels

Package: nuxtIssues related to the Sentry Nuxt SDK

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions