Skip to content

[@sentry/sveltekit] ReferenceError: Cannot access 'default' before initialization. when version uses execSync or equivalent sync call #17510

@hloth

Description

@hloth

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/sveltekit

SDK Version

^10

Framework Version

sveltejs/kit@^2.37.0 + svelte@^5.38.6

Link to Sentry event

No response

Reproduction Example/SDK Setup

svelte.config.js:

import { execSync } from 'node:child_process'
import adapter from '@sveltejs/adapter-node'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

const config = {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter(),

    version: {
      name:
        execSync('git rev-parse HEAD').toString().trimEnd().substring(0, 7) +
        '/' +
        process.env.PUBLIC_APP_ENV
    },

    experimental: {
      tracing: {
        server: true
      },

      instrumentation: {
        server: true
      }
    }
  }
}

export default config

Steps to Reproduce

  1. Create svelte kit project
  2. Put svelte.config.js above
  3. Run project

Without version, with async version getting or without sentry source map plugin it works fine.

See https://svelte.dev/docs/kit/configuration#version

Expected Result

Version loads and source map plugin works

Actual Result

[Source Maps Plugin] Couldn't load svelte.config.js:
16 |   try {
17 |     if (!fs.existsSync(configFile)) {
18 |       return {};
19 |     }
20 |     // @ts-expect-error - we explicitly want to import the svelte config here.
21 |     const svelteConfigModule = await import(`${url.pathToFileURL(configFile).href}`);
                                                                                  ^
ReferenceError: Cannot access 'default' before initialization.
      at loadSvelteConfig (/path/to/node_modules/@sentry/sveltekit/build/esm/vite/svelteConfig.js:21:78)
      at spawnSync (node:child_process:226:22)
      at execSync (node:child_process:275:109)
      at /path/to/svelte.config.js:12:9
      at requestImportModule (2:1)

Metadata

Metadata

Assignees

Projects

Status

Waiting for: Community

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions