Skip to content

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

Closed
@haines

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/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@sentry/src/utils/instrumentServer.ts:519:36)
  at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@sentry/src/utils/instrumentServer.ts:565:36)
  at createRequestHandler (node_modules/.pnpm/@[email protected][email protected][email protected]/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).

Metadata

Metadata

Assignees

Labels

Package: remixIssues related to the Sentry Remix SDK

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions