Skip to content

feat(nuxt): allow custom configuration files paths in Nuxt module#20650

Open
victorgarciaesgi wants to merge 11 commits intogetsentry:developfrom
victorgarciaesgi:develop
Open

feat(nuxt): allow custom configuration files paths in Nuxt module#20650
victorgarciaesgi wants to merge 11 commits intogetsentry:developfrom
victorgarciaesgi:develop

Conversation

@victorgarciaesgi
Copy link
Copy Markdown

@victorgarciaesgi victorgarciaesgi commented May 4, 2026

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

Context

I work in a big monorepo with 60+ Nuxt apps.

To enable Sentry in all those apps, they use a shared configuration, handled by an internal "proxy" module.
Each app can just install and enable this module to share the same common configuration.

The problem is: with the official Sentry module, each app would have to declare its own:

  • sentry.client.config.ts
  • sentry.server.config.ts

Which isn't very convenient when we have 60+ apps to enable.

Basically in the "proxy" module, I wanted to do this:

setup(options, nuxt) {
     const {resolve} = createResolver(import.meta.url);

     await installModule('@sentry/nuxt/module', {
           configRootDir: resolve('./runtime'),
     });
}

Result

This PR adds configDir option to the Nuxt module, allowing more flexible configuration and avoid creating a sentry.**.config.ts for each app 👌

The module can now search in a custom directory path instead of the project root path.

I'm successfully running this change as a pnpm patch on my monorepo so I wanted to contribute it.

@victorgarciaesgi victorgarciaesgi requested a review from a team as a code owner May 4, 2026 12:51
}

const serverConfigFile = findDefaultSdkInitFile('server', nuxt);
const serverConfigFile = await findDefaultSdkInitFile('server', nuxt, moduleOptions);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The check for serverConfigFile requires the filename to include .server.config, which silently skips server-side Sentry initialization if a custom filename is used.
Severity: HIGH

Suggested Fix

The check if (serverConfigFile?.includes('.server.config')) is too restrictive and should be removed. The presence of the serverConfigFile option should be sufficient to trigger the necessary server build steps, allowing any custom file path as intended.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/nuxt/src/module.ts#L82

Potential issue: When a custom `serverConfigFile` path is provided, a check requires the
resolved path to contain the string `.server.config`. If a user provides a custom
filename that doesn't match this convention, such as `server-sentry-init.ts`, the check
fails. This silently skips critical server build steps, including
`addServerConfigToBuild` and `addSentryTopImport`, preventing the custom configuration
from being bundled and preloaded. As a result, server-side Sentry initialization fails
without any warning, even though the feature is intended to support any file path.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment thread packages/nuxt/src/module.ts
Comment thread packages/nuxt/test/vite/utils.test.ts Outdated

expect(result).toBe(expectedPath);
expect(resolvePathMock).toHaveBeenCalledWith('~/server-sentry-config.ts');
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feat PR lacks integration or E2E test coverage

Low Severity

This feat PR only includes unit tests for findDefaultSdkInitFile and a type test. Per project rules, feat PRs need at least one integration or E2E test to verify the full feature works end-to-end (e.g., that a custom config file is correctly picked up and wired through the Nuxt module setup).

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit b947a37. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a Nuxt module related change, I couln't find the need for an integration test

Comment thread packages/nuxt/src/vite/utils.ts Outdated
Comment thread packages/nuxt/src/vite/utils.ts Outdated
}
} catch {
// Fails silently as the file is optional
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom server config paths skip critical server-side setup

High Severity

When a custom serverConfigFile path is provided that doesn't contain the substring .server.config (e.g. the documented example ~/server-sentry-config.ts), the guard at module.ts line 173 (serverConfigFile?.includes('.server.config')) evaluates to false. This silently skips all critical server-side setup: addServerConfigToBuild, addSentryTopImport, and addDynamicImportEntryFileWrapper. The server SDK will register plugins but never actually load the config file, making autoInjectServerSentry non-functional for custom-named config files.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 490c666. Configure here.

Comment thread packages/nuxt/src/vite/utils.ts Outdated
Comment thread packages/nuxt/src/vite/utils.ts Outdated
Copy link
Copy Markdown
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution!

Just a general question: how does your setup look like? Because in case you are using Nuxt layers, a shared config already works.

Comment thread packages/nuxt/src/common/types.ts Outdated
Comment thread packages/nuxt/src/common/types.ts Outdated
* }
* ```
*/
clientConfigFile?: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding clientConfigPath and serverConfigPath?
So you can provide a specific pathname to a folder where the SDK will look for the config.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that seems better i'll change it 👍
I've not handled the case of a folder path, could a single configRootDir: string work better? That way it works for both client and server

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that would be even better. You could call it configDir. The root part is a bit misleading as it's just a simple path for where we can find the config.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s1gr1d I implemented the single configRootDir, which is much simpler to use & implement 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't see your comment, renamed it 👌

@victorgarciaesgi
Copy link
Copy Markdown
Author

victorgarciaesgi commented May 4, 2026

Hey @s1gr1d thanks for the fast response!

We're not using layers yet, our structure basically looks like this:

app-1/
app-2/
lib-nuxt/
├─ internal-sentry-module/

app-1 would declare "internal-sentry-module": "workspace:*" in its package.json.
Then a common Nuxt config declares the sentry module.

victorgarciaesgi and others added 2 commits May 4, 2026 15:50
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
Comment thread packages/nuxt/src/vite/utils.ts
Comment thread packages/nuxt/src/vite/utils.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 207be84. Configure here.

Comment thread packages/nuxt/src/vite/utils.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants