Skip to content

fix(nuxt): Add @sentry/nuxt as external in Rollup #16407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 28, 2025

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented May 28, 2025

The Sentry Nuxt SDK emits the Sentry config file during the Rollup build. Users add this file to their application which includes an import from @sentry/nuxt and the init function. This file is then added as an .mjs file in the build output.

However, when building the application, this .mjs file included a bunch of OpenTelemetry imports and not only the init code as every dependency from @sentry/nuxt was traced back and bundled into the build output.

By adding @sentry/nuxt as external, the .mjs file really only contains the content like in the .ts file.

Could fix #15204

@s1gr1d s1gr1d self-assigned this May 28, 2025
apply(target, thisArg, args: [string, string | undefined, boolean]) {
const [source] = args;
if (
sentryExternals.some(external => (typeof external === 'string' ? source === external : external.test(source)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Are we ever expecting more than one external here? The comment and function name make it sound like it's always only going to be @sentry/nuxt and nothing else. I feel like we can just simplify this code to /^@sentry\/nuxt$/.test(source)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, I had 'import-in-the-middle' added to the array at first as well. But as this is actually not necessary, I can remove it 👍

* that would result in adding imports from OpenTelemetry libraries etc. to the server build.
*/
export function getExternalOptionsWithSentryNuxt(previousExternal: ExternalOption | undefined): ExternalOption {
const sentryExternals = [/^@sentry\/nuxt$/];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Technically, I don't think this needs to be an array at all, right? Just thinking that the .some call below as well as the object spreads are kinda unnecessary if we only have one element in the array (in the sense of a slight perf overhead as well as code readability).

(I read Andrei's comment, so feel free to ignore this if I happen to review in an in-between state 😅)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lms24 simplified.

@andreiborza andreiborza requested a review from Lms24 May 28, 2025 11:32
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for making the changes!

@andreiborza andreiborza merged commit 6e61f82 into develop May 28, 2025
159 checks passed
@andreiborza andreiborza deleted the sig/nuxt-rollup-external branch May 28, 2025 12:28
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.

Nuxt: Cannot find module: node_modules\@opentelemetry\resources\build\esm\detectors\platform\node\machine-id\execAsync
3 participants