You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(nuxt): Make dynamic import() wrapping default (#13958)
BREAKING CHANGE: The `--import` flag must not be added anymore. If it is
still set, the server-side will be initialized twice and this leads to
unexpected errors.
---
First merge this:
#13945
Part of this:
#13943
This PR makes it the default to include a rollup plugin that wraps the
server entry file with a dynamic import (`import()`). This is a
replacement for the node `--import` CLI flag.
If you still want to manually add the CLI flag you can use this option
in the `nuxt.config.ts` file:
```js
sentry: {
dynamicImportForServerEntry: false,
}
```
(option name is up for discussion)
Copy file name to clipboardExpand all lines: packages/nuxt/src/common/types.ts
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -103,16 +103,19 @@ export type SentryNuxtModuleOptions = {
103
103
debug?: boolean;
104
104
105
105
/**
106
-
* Enabling basic server tracing can be used for environments where modifying the node option `--import` is not possible.
107
-
* However, enabling this option only supports limited tracing instrumentation. Only http traces will be collected (but no database-specific traces etc.).
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
108
*
109
-
* If this option is `true`, the Sentry SDK will import the Sentry server config at the top of the server entry file to load the SDK on the server.
109
+
* If this option is `false`, the Sentry SDK won't wrap the server entry file with `import()`. Not wrapping the
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.
110
112
*
111
-
* **DO NOT** enable this option if you've already added the node option `--import` in your node start script. This would initialize Sentry twice on the server-side and leads to unexpected issues.
113
+
* **DO NOT** add the node CLI flag `--import` in your node start script, when `dynamicImportForServerEntry` is set to `true` (default).
114
+
* This would initialize Sentry twice on the server-side and this leads to unexpected issues.
112
115
*
113
-
* @defaultfalse
116
+
* @defaulttrue
114
117
*/
115
-
experimental_basicServerTracing?: boolean;
118
+
dynamicImportForServerEntry?: boolean;
116
119
117
120
/**
118
121
* 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.
`[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`,
106
-
);
107
-
});
108
-
}
109
-
});
110
-
});
111
-
}catch(err){
112
-
if(moduleOptions.debug){
113
-
consoleSandbox(()=>{
114
-
// eslint-disable-next-line no-console
115
-
console.warn(
116
-
`[Sentry] An error occurred when trying to add the Sentry import to the server entry file "\`${entryFilePath}\`":`,
117
-
err,
118
-
);
119
-
});
120
-
}
121
-
}
122
-
});
123
-
}
124
-
125
77
/**
126
78
* This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)
127
79
* and adds the Sentry server config with the static `import` declaration.
@@ -187,11 +139,8 @@ function wrapEntryWithDynamicImport(resolvedSentryConfigPath: string): InputPlug
187
139
: resolution.id
188
140
// 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)
@@ -211,7 +160,7 @@ function wrapEntryWithDynamicImport(resolvedSentryConfigPath: string): InputPlug
211
160
// `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)
212
161
`import(${JSON.stringify(entryId)});\n`+
213
162
// 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()`.
0 commit comments