Skip to content

Commit a0079a8

Browse files
committed
nuxt: fix getting client
1 parent e1f1ade commit a0079a8

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

packages/nuxt/src/client/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { init as initBrowser } from '@sentry/browser';
22
import { applySdkMetadata } from '@sentry/core';
33
import type { Client } from '@sentry/types';
4-
import type { SentryVueOptions } from '../common/types';
4+
import type { SentryNuxtOptions } from '../common/types';
55

66
/**
77
* Initializes the client-side of the Nuxt SDK
88
*
99
* @param options Configuration options for the SDK.
1010
*/
11-
export function init(options: SentryVueOptions): Client | undefined {
11+
export function init(options: SentryNuxtOptions): Client | undefined {
1212
const sentryOptions = {
1313
...options,
1414
};

packages/nuxt/src/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import type { init } from '@sentry/vue';
22

33
// Omitting 'app' as the Nuxt SDK will add the app instance in the client plugin (users do not have to provide this)
4-
export type SentryVueOptions = Omit<Parameters<typeof init>[0] & object, 'app'>;
4+
export type SentryNuxtOptions = Omit<Parameters<typeof init>[0] & object, 'app'>;

packages/nuxt/src/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import { type Resolver, addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';
44
import { addImportStatement, buildSdkInitFileImportSnippet } from './common/snippets';
5-
import type { SentryVueOptions } from './common/types';
5+
import type { SentryNuxtOptions } from './common/types';
66

7-
export type ModuleOptions = SentryVueOptions;
7+
export type ModuleOptions = SentryNuxtOptions;
88

99
export default defineNuxtModule<ModuleOptions>({
1010
meta: {
11-
name: '@sentry/nuxt',
11+
name: '@sentry/nuxt/module',
1212
configKey: 'sentry',
1313
compatibility: {
1414
nuxt: '^3.0.0',
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import * as Sentry from '@sentry/vue';
1+
import { getClient } from '@sentry/core';
2+
import { vueIntegration } from '@sentry/vue';
23
import { defineNuxtPlugin } from 'nuxt/app';
34

45
export default defineNuxtPlugin(nuxtApp => {
56
nuxtApp.hook('app:created', vueApp => {
6-
Sentry.addIntegration(Sentry.vueIntegration({ app: vueApp }));
7+
const sentryClient = getClient();
8+
9+
if (sentryClient) {
10+
sentryClient.addIntegration(vueIntegration({ app: vueApp }));
11+
}
712
});
813
});

packages/nuxt/test/client/sdk.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import * as SentryBrowser from '@sentry/browser';
12
import { SDK_VERSION } from '@sentry/vue';
2-
import * as SentryVue from '@sentry/vue';
33
import { beforeEach, describe, expect, it, vi } from 'vitest';
44
import { init } from '../../src/client';
55

6-
const vueInit = vi.spyOn(SentryVue, 'init');
6+
const vueInit = vi.spyOn(SentryBrowser, 'init');
77

88
describe('Nuxt Client SDK', () => {
99
describe('init', () => {

0 commit comments

Comments
 (0)