Skip to content

Can't instrument Remix server build with Express and Vite dev server #10724

Closed

Description

@haines

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/remix

SDK Version

7.101.1

Framework Version

2.6.0

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

Follow the Remix Vite migration guide with a custom Express app server. Specifically, use the Vite dev server in middleware mode and pass a function to createRequestHandler.

  createRequestHandler({
    build: viteDevServer
      ? () =>
          viteDevServer.ssrLoadModule(
            "virtual:remix/server-build"
          )
      : await import("./build/server/index.js"),
  })

Expected Result

Sentry instruments the server build whether it is passed as a function or a static build. If the server build is a function, Sentry wraps the function and instruments the result when it is called.

Actual Result

Sentry's monkey patch fails with an error.

TypeError: Cannot read properties of undefined (reading 'module')
  at instrumentBuild (node_modules/.pnpm/@sentry+remix@7.101.1_@remix-run+node@2.6.0_@remix-run+react@2.6.0_react@18.2.0/node_modules/@sentry/src/utils/instrumentServer.ts:519:36)
  at Object.<anonymous> (node_modules/.pnpm/@sentry+remix@7.101.1_@remix-run+node@2.6.0_@remix-run+react@2.6.0_react@18.2.0/node_modules/@sentry/src/utils/instrumentServer.ts:565:36)
  at createRequestHandler (node_modules/.pnpm/@remix-run+express@2.6.0_express@4.18.2_typescript@5.3.3/node_modules/@remix-run/express/dist/server.js:36:28)

This was previously marked as resolved (#9500) by a workaround that was added to the docs where instead of passing the build as a function, you instead have to call the function and await the result. But as mentioned in this comment, that is not a good idea because it breaks HDR (the whole point of passing the function is that it is re-evaluated on every request, so that in dev you always get the latest server build after making changes, without having to reload the app server).

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Feb 19, 2024
  2. lforst commented on Feb 22, 2024

    @lforst
    Contributor

    Hi, sorry for the late reply, we are taking a look at this!

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Feb 22, 2024
  4. added a commit that references this issue on Feb 26, 2024
    d570594
  5. AbhiPrasad commented on Feb 26, 2024

    @AbhiPrasad
    Contributor

    we merged this fix in, but now have to backport this onto the v7 branch - so re-opening issue until release is cut there.

  6. added 3 commits that reference this issue on Feb 26, 2024
    c2d21cf
    7634793
    618b7d7
  7. added a commit that references this issue on Mar 7, 2024
    7ed95c1
  8. AbhiPrasad commented on Mar 8, 2024

    @AbhiPrasad
    Contributor
  9. ghost added on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions