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

Requires +page.{tj}s file when using sveltekit and Houdini #8846

Closed
3 tasks done
lukaso opened this issue Aug 18, 2023 · 9 comments · Fixed by #8881
Closed
3 tasks done

Requires +page.{tj}s file when using sveltekit and Houdini #8846

lukaso opened this issue Aug 18, 2023 · 9 comments · Fixed by #8881

Comments

@lukaso
Copy link

lukaso commented Aug 18, 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

Sveltekit 1.22.4

Link to Sentry event

No response

SDK Setup

    Sentry.init({
      dsn: PUBLIC_SENTRY_DSN,
      tracesSampleRate: 1.0,

      // This sets the sample rate to be 10%. You may want this to be 100% while
      // in development and sample at a lower rate in production
      replaysSessionSampleRate: 0.1,

      // If the entire session is not sampled, use the below sample rate to sample
      // sessions when an error occurs.
      replaysOnErrorSampleRate: 1.0,

      // If you don't want to use Session Replay, just remove the line below:
      integrations: [new Replay()],
    });

Steps to Reproduce

  1. Create a project
  2. Set +layout.js or ts to export const ssr = false (don't know if this is relevant to reproducing)
  3. Add in sentry
  4. Create a route and add a +page.svelte
  5. Do not create a +page.ts or a +page.js
  6. Run the project using pnpm dev

Expected Result

The project runs

Actual Result

This happens for any page in the routes, so it doesn't matter what the path is.

Internal server error: ENOENT: no such file or directory, open '/src/routes/(app)/projects/[projectid]/settings/+page.js'
  
[Error: ENOENT: no such file or directory, open '/src/routes/(app)/projects/[projectid]/settings/+page.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/src/routes/(app)/projects/[projectid]/settings/+page.js'
}
@Lms24
Copy link
Member

Lms24 commented Aug 18, 2023

Hi @lukaso thanks for writing in!

I tried to reproduce this by following your reproduction instructions and I didn't encounter the mentioned error.

Can you please take a look at my reproduction and point out what to change so that the error occurs? Alternatively, please share your own reproduction (e.g. via a GH repo) so that we can investigate this further. Thanks!

@lukaso
Copy link
Author

lukaso commented Aug 20, 2023

OK, a little progress. I haven't been able to reproduce it with your repo, but I've been able to stop the problem with mine. I added autoinstrument: true to the vite.config.js sentrySveltekit statement and the problem went away. No idea why.

Unfortunately, removing autoinstrument: true from yours (I restarted from scratch) isn't enough to bring the problem back and also, now, when I remove it from mine, the problem also doesn't come back.

I don't know if that helps a little. I'll try to reproduce it, but it seems very strange.

@lukaso
Copy link
Author

lukaso commented Aug 20, 2023

Once I did an pnpm build however, that hadn't actually fixed the problem. Will keep digging.

@lukaso
Copy link
Author

lukaso commented Aug 20, 2023

OK, I can reproduce it with this: https://github.com/lukaso/gh-sentry-javascript-8846-sveltekit-file-not-found/tree/reproduce

It appears there's a bad interaction between houdini and sentry.

@Lms24
Copy link
Member

Lms24 commented Aug 21, 2023

Thanks for tracking this down! I'll take a look at this next week, this week is kinda full already. Backlogged it for the moment.

@Lms24 Lms24 self-assigned this Aug 21, 2023
@lukaso
Copy link
Author

lukaso commented Aug 21, 2023

No problem. I have a workaround so it's fine for now.

@Lms24
Copy link
Member

Lms24 commented Aug 28, 2023

I looked into this and it seems like Houdini adds file ids to the build that didn't exist before, such as the aforementioned +page.js file. When our auto instrumentation plugin's load hook is called, we previously tried to read the file id (if the filename matched +(page|layout)(.server)?.(js|ts)) and didn't check if the file actually existed.

Consequently, the ids added by Houdini matched our filename filter, we tried to read them and... the build crashed because the file didn't exist.

I opened #8881 to guard reading the file by checking for its existence.

Note, I didn't find the code responsible for adding these file ids in Houdini. cc @jycouet @AlecAivazis is this intended behaviour? Are these files added so that Houdini can be used in routes without previously existing +page.ts (etc) files? As I said we can easily guard for this but just wanted to let you know that this might be problematic for other plugins as well.

@Lms24 Lms24 changed the title Requires +page.{tj}s file when using sveltekit Requires +page.{tj}s file when using sveltekit and Houdini Aug 28, 2023
@lukaso
Copy link
Author

lukaso commented Aug 28, 2023

Thanks for figuring this out! Really appreciated. Which version will the fix land in (if you know)?

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.
@Lms24
Copy link
Member

Lms24 commented Aug 29, 2023

I just merged the fix so it'll go out in the next release. This will either be 7.65.1 or 7.66.0 (depending on what else we merge in). You can expect it to be released sometime this or, latest, next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
3 participants