Skip to content
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

Automatic sveltekit load instrumentation causes vite bundle errors with duplicate identifier "load" #8854

Closed
3 tasks done
fnimick opened this issue Aug 21, 2023 · 3 comments · Fixed by #8881
Closed
3 tasks done

Comments

@fnimick
Copy link

fnimick commented Aug 21, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/sveltekit

SDK Version

7.64.0

Framework Version

1.22.6

Link to Sentry event

No response

SDK Setup

Sentry.init({
    dsn: "https://7f6570917828021f8dea53dc2b778775@o1098001.ingest.sentry.io/4505744165699584",
    tracesSampleRate: 1
})

Steps to Reproduce

I added the Sentry SDK to a Sveltekit project using the wizard.

My vite config is:

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      sourceMapsUploadOptions: {
        org: "million-marker",
        project: "future",
      },
      debug: true,
    }),
    houdini(),
    sveltekit(),
    Icons({ compiler: "svelte" }),
    svg({
      svgoOptions: {
        plugins: [
          {
            name: "preset-default",
            params: { overrides: { removeViewBox: false } },
          },
          {
            name: "prefixIds",
          },
        ],
      },
    }),
  ],
  ssr: {
    // Prevent crashes in SSR when Felte forms are used. See
    // https://github.com/pablo-abc/felte/issues/201#issuecomment-1381641343
    noExternal: ["felte"],
  },
});

Expected Result

No crash when running in development

Actual Result

Upon starting a dev server, I immediately receive errors due to the automatic load instrumentation. With the plugin debug option enabled:

Wrapping /Users/francis/millionmarker/future/src/routes/+layout.ts with Sentry load wrapper
Wrapping /Users/francis/millionmarker/future/src/routes/(app)/+page.ts with Sentry load wrapper
Internal server error: ENOENT: no such file or directory, open '/src/routes/(app)/+layout.js'
   (x2)
Internal server error: Transform failed with 2 errors:
/Users/francis/millionmarker/future/src/routes/+layout.ts:13:13: ERROR: Multiple exports with the same name "load"
/Users/francis/millionmarker/future/src/routes/+layout.ts:13:13: ERROR: The symbol "load" has already been declared
  Plugin: vite:esbuild
  File: /Users/francis/millionmarker/future/src/routes/+layout.ts:13:13
  
  Multiple exports with the same name "load"
  11 |  }
  12 |  
  13 |  export const load = userModule.load ? wrapLoadWithSentry(userModule.load) : undefined;
     |               ^
  14 |  export * from "/Users/francis/millionmarker/future/src/routes/+layout.ts?sentry-auto-wrap";
  
  The symbol "load" has already been declared
  11 |  }
  12 |  
  13 |  export const load = userModule.load ? wrapLoadWithSentry(userModule.load) : undefined;
     |               ^
  14 |  export * from "/Users/francis/millionmarker/future/src/routes/+layout.ts?sentry-auto-wrap";

@Lms24
Copy link
Member

Lms24 commented Aug 21, 2023

Hi @fnimick thanks for reporting this! Hmm looking at your config, it seems like you have quite a few plugins running that might interfere with our auto instrumentation in some way. I have a hunch that it might be houdini, given that a very similar issue was reported a couple of days ago (#8846). Can you try removing houdini and check if this solves the issue?

As I wrote in #8646, we'll look into Sentry+Houdini next week.

If it turns out not to be related to Houdini, please try to narrow it down to a specific plugin combination and if possible, provide a minimal reproduction example that we can use to reproduce this. Thanks!

@fnimick
Copy link
Author

fnimick commented Aug 21, 2023

@Lms24 ah, you were right, it is a Houdini compatibility issue. I didn't expect it since houdini was not in use at all on the route that was causing the error.

@Lms24
Copy link
Member

Lms24 commented Aug 28, 2023

@fnimick I opened #8881 which should fix this issue. It'll go in the next patch or minor release after today's release.

Lms24 added a commit that referenced this issue Aug 29, 2023
…mentation (#8881)

In our auto instrumentation Vite plugin for SvelteKit, we read
`+(page|layout)(.server).(js|ts)` files' code to determine if we should
add our wrapper to the file or not. We previously didn't check for a
file id's existence before reading the file if the id matched that
certain pattern, wrongly assuming that these ids would always map to
actually existing files.

It seems like Vite plugins such as Houdini's plugin add file ids to the
build for files that actually don't exist (#8846, #8854) . When our
plugin's `load` hook was called for such an id, it then tried to access
and read the file which caused a build error.

This patch now adds a file existence guard to ensure we simply no-op for
these files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
2 participants