Skip to content

Commit 64ef553

Browse files
authored
fix(nuxt): include sentry.client.config.ts in nuxt app types (#17830)
# What Fixes #17781 by adding the `sentry.config.client.ts` to the auto generated tsconfig by extending the types via the [`prepare:types` hook](https://nuxt.com/docs/4.x/guide/going-further/modules#adding-type-declarations). This allows `useRuntimeConfig` to be properly typed in the root `sentry.client.config.ts`, or where ever the client file is found. Not sure how this could be tested tho, since it is purely types. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds a `prepare:types` hook to include the client Sentry config in Nuxt’s generated `tsconfig` for proper typing. > > - **Nuxt module (`packages/nuxt/src/module.ts`)**: > - **Types setup**: Add `prepare:types` hook to ensure `tsconfig.include` contains the relative path to the detected client Sentry config (`sentry.client.config.ts`), enabling proper typing (e.g., `useRuntimeConfig`) in root config files for Nuxt v4. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4de6d43. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5aa7a53 commit 64ef553

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/nuxt/src/module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export default defineNuxtModule<ModuleOptions>({
7272
mode: 'client',
7373
order: 1,
7474
});
75+
76+
// Add the sentry config file to the include array
77+
nuxt.hook('prepare:types', options => {
78+
if (!options.tsConfig.include) {
79+
options.tsConfig.include = [];
80+
}
81+
82+
// Add type references for useRuntimeConfig in root files for nuxt v4
83+
// Should be relative to `root/.nuxt`
84+
const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);
85+
options.tsConfig.include.push(relativePath);
86+
});
7587
}
7688

7789
const serverConfigFile = findDefaultSdkInitFile('server', nuxt);

0 commit comments

Comments
 (0)