Skip to content

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

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

feat(nuxt): allow custom configuration files paths in Nuxt module#20650
victorgarciaesgi wants to merge 16 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
Comment thread packages/nuxt/src/module.ts
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 Outdated
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
Comment thread packages/nuxt/src/vite/utils.ts Outdated
Comment thread packages/nuxt/src/common/types.ts Outdated
Comment thread packages/nuxt/src/common/types.ts Outdated
Comment thread packages/nuxt/src/common/types.ts Outdated
victorgarciaesgi and others added 2 commits May 5, 2026 15:20
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
@victorgarciaesgi
Copy link
Copy Markdown
Author

Suggestions applied 👌

victorgarciaesgi and others added 2 commits May 6, 2026 15:24
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
Comment on lines 59 to 65
}

// As a fallback, also check CWD (left for pure compatibility)
const cwd = process.cwd();
const rootDir = options?.configDir ? await resolvePath(options.configDir, { type: 'dir' }) : process.cwd();
for (const relativePath of relativePaths) {
const fullPath = path.resolve(cwd, relativePath);
const fullPath = path.resolve(rootDir, relativePath);
if (fs.existsSync(fullPath)) {
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 configDir option is only used as a fallback. If a Sentry config file exists in the project root (a default Nuxt layer), the configDir is silently ignored.
Severity: MEDIUM

Suggested Fix

Prioritize the configDir if it is provided. Before iterating through Nuxt layers, check if options.configDir is set. If it is, search for the configuration file exclusively within that directory. The layer-based search should only be used as a fallback when configDir is not specified.

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/vite/utils.ts#L59-L65

Potential issue: The logic for finding the Sentry SDK init file prioritizes searching
through all Nuxt layers before considering the `configDir` option. In a standard Nuxt
application, the project root is one of the layers. Consequently, if a
`sentry.client.config.ts` or `sentry.server.config.ts` file is present in the project
root, it will be used, and the path specified in `configDir` will be silently ignored.
This contradicts the documented behavior that `configDir` should replace the default
lookup location, leading to unexpected configuration being loaded. The fallback comment
'As a fallback, also check CWD' confirms this last-resort implementation.

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