Skip to content

Don't insert Svelte preprocessor code in script module in Svelte 5. #17113

@richardjelinek-fastest

Description

@richardjelinek-fastest

Here is the diff that solved my problem:

diff --git a/node_modules/@sentry/svelte/build/esm/preprocessors.js b/node_modules/@sentry/svelte/build/esm/preprocessors.js
index 62f0b46..600c653 100644
--- a/node_modules/@sentry/svelte/build/esm/preprocessors.js
+++ b/node_modules/@sentry/svelte/build/esm/preprocessors.js
@@ -95,7 +95,7 @@ function shouldInjectFunction(
   // because the code inside is not executed when the component is instantiated but
   // when the module is first imported.
   // see: https://svelte.dev/docs#component-format-script-context-module
-  if (attributes.context === 'module') {
+  if (attributes.module || attributes.context === 'module') {
     return false;
   }
 

The attributes changed in Svelte 5. In asynchronously loaded components it started to fail.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions