Skip to content

Commit e12c03c

Browse files
committed
fix dev mode
1 parent 5b12bc4 commit e12c03c

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

packages/nuxt/src/common/types.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,19 @@ export type SentryNuxtModuleOptions = {
103103
debug?: boolean;
104104

105105
/**
106+
* Wraps the server entry file with a dynamic `import()`. This will make it possible to preload Sentry and register
107+
* necessary hooks before other code runs. (Node docs: https://nodejs.org/api/module.html#enabling)
108+
*
106109
* If this option is `false`, the Sentry SDK won't wrap the server entry file with `import()`. Not wrapping the
107-
* server entry file will disable Sentry on the server-side. When you set this option to `true`, make sure
108-
* to add the sentry server config with the node `--import` CLI flag to enable Sentry on the server-side.
110+
* server entry file will disable Sentry on the server-side. When you set this option to `false`, make sure
111+
* to add the Sentry server config with the node `--import` CLI flag to enable Sentry on the server-side.
109112
*
110-
* **DO NOT** add the node CLI flag `--import` in your node start script, when `disableDynamicImportWrapping` is set to `false`.
113+
* **DO NOT** add the node CLI flag `--import` in your node start script, when `dynamicImportWrapping` is set to `true` (default).
111114
* This would initialize Sentry twice on the server-side and this leads to unexpected issues.
112115
*
113-
* @default false
116+
* @default true
114117
*/
115-
disableDynamicImportWrapping?: boolean;
118+
dynamicImportWrapping?: boolean;
116119

117120
/**
118121
* Options to be passed directly to the Sentry Rollup Plugin (`@sentry/rollup-plugin`) and Sentry Vite Plugin (`@sentry/vite-plugin`) that ship with the Sentry Nuxt SDK.

packages/nuxt/src/module.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export default defineNuxtModule<ModuleOptions>({
1717
},
1818
},
1919
defaults: {},
20-
setup(moduleOptions, nuxt) {
20+
setup(moduleOptionsParam, nuxt) {
21+
const moduleOptions = {
22+
...moduleOptionsParam,
23+
dynamicImportWrapping: moduleOptionsParam.dynamicImportWrapping !== false, // default: true
24+
};
25+
2126
const moduleDirResolver = createResolver(import.meta.url);
2227
const buildDirResolver = createResolver(nuxt.options.buildDir);
2328

@@ -48,7 +53,7 @@ export default defineNuxtModule<ModuleOptions>({
4853
const serverConfigFile = findDefaultSdkInitFile('server');
4954

5055
if (serverConfigFile) {
51-
if (moduleOptions.disableDynamicImportWrapping) {
56+
if (moduleOptions.dynamicImportWrapping === false) {
5257
// Inject the server-side Sentry config file with a side effect import
5358
addPluginTemplate({
5459
mode: 'server',
@@ -69,7 +74,7 @@ export default defineNuxtModule<ModuleOptions>({
6974

7075
nuxt.hooks.hook('nitro:init', nitro => {
7176
if (serverConfigFile && serverConfigFile.includes('.server.config')) {
72-
if (moduleOptions.disableDynamicImportWrapping) {
77+
if (moduleOptions.dynamicImportWrapping === false) {
7378
addServerConfigToBuild(moduleOptions, nuxt, nitro, serverConfigFile);
7479

7580
if (moduleOptions.debug) {

packages/nuxt/src/vite/addServerConfig.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,8 @@ function wrapEntryWithDynamicImport(resolvedSentryConfigPath: string): InputPlug
139139
: resolution.id
140140
// Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)
141141
.concat(SENTRY_WRAPPED_ENTRY)
142-
.concat(
143-
exportedFunctions?.length
144-
? SENTRY_FUNCTIONS_REEXPORT.concat(exportedFunctions.join(',')).concat(QUERY_END_INDICATOR)
145-
: '',
146-
);
142+
.concat(exportedFunctions?.length ? SENTRY_FUNCTIONS_REEXPORT.concat(exportedFunctions.join(',')) : '')
143+
.concat(QUERY_END_INDICATOR);
147144
}
148145
return null;
149146
},
@@ -163,7 +160,7 @@ function wrapEntryWithDynamicImport(resolvedSentryConfigPath: string): InputPlug
163160
// `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)
164161
`import(${JSON.stringify(entryId)});\n` +
165162
// By importing "import-in-the-middle/hook.mjs", we can make sure this file wil be included, as not all node builders are including files imported with `module.register()`.
166-
"import 'import-in-the-middle/hook.mjs'\n" +
163+
"import 'import-in-the-middle/hook.mjs';\n" +
167164
`${reExportedFunctions}\n`
168165
);
169166
}

packages/nuxt/test/vite/utils.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ describe('findDefaultSdkInitFile', () => {
7171
describe('removeSentryQueryFromPath', () => {
7272
it('strips the Sentry query part from the path', () => {
7373
const url = `/example/path${SENTRY_WRAPPED_ENTRY}${SENTRY_FUNCTIONS_REEXPORT}foo,${QUERY_END_INDICATOR}`;
74+
const url2 = `/example/path${SENTRY_WRAPPED_ENTRY}${QUERY_END_INDICATOR}`;
7475
const result = removeSentryQueryFromPath(url);
76+
const result2 = removeSentryQueryFromPath(url2);
7577
expect(result).toBe('/example/path');
78+
expect(result2).toBe('/example/path');
7679
});
7780

7881
it('returns the same path if the specific query part is not present', () => {

0 commit comments

Comments
 (0)