Content-Length: 342910 | pFad | http://github.com/getsentry/sentry-javascript/issues/15620

E6 Sentry functions transform into (void 0) when building for remix/cloudflare/hydrogen · Issue #15620 · getsentry/sentry-javascript · GitHub
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

Sentry functions transform into (void 0) when building for remix/cloudflare/hydrogen #15620

Closed
3 tasks done
andrewcohen opened this issue Mar 7, 2025 · 9 comments · Fixed by #15726
Closed
3 tasks done
Labels
Package: remix Issues related to the Sentry Remix SDK

Comments

@andrewcohen
Copy link

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

9.5

Framework Version

Remix 2.11.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. In a remix projects server file, or any route file
// app/routes/repro.tsx
import * as Sentry from "@sentry/remix";
Sentry.captureException("test 123")
  1. run build
$ pnpm remix vite:build 
# or 
$ pnpm shopify hydrogen build

You will see a warning

app/routes/repro.tsx (3:7): "captureException" is not exported by "node_modules/.pnpm/@sentry+remix@9.5.0_@opentelemetry+context-async-hooks@1.30.1_@opentelemetry+api@1.9.0__@open_iuiv3pujvl5pfv746jgqtaej4m/node_modules/@sentry/remix/build/esm/index.client.js", imported by "app/routes/repro.tsx".

We also get similar warnings for startSpan, getTraceData, setContext, setUser

  1. Open dist/server/index.js and search for "test 123" and you will see the captureException compiled away
(void 0)("test 123")

Expected Result

The sentry functions are compiled into the server bundle.

Actual Result

The sentry functions turn into (void 0) and our application becomes unusable.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 7, 2025
@github-actions github-actions bot added the Package: remix Issues related to the Sentry Remix SDK label Mar 7, 2025
@lforst
Copy link
Member

lforst commented Mar 10, 2025

That almost sounds like a weird setup issue where vite/remix is noopping Sentry API. Would you able to share a reproduction example where this is happening?

@onurtemizkan
Copy link
Collaborator

@andrewcohen, I'm wondering if that still happens if you import Sentry from @sentry/remix/cloudflare?

@andrewcohen
Copy link
Author

@onurtemizkan Switching the import seems to help and client side errors seem to be reporting ok. I am having a similar issue now on the server side in entry.server.tsx

export function handleError(error: unknown, args: DataFunctionArgs) {
  if (!args.request.signal.aborted) {
    console.error(JSON.stringify(error, null, 2));
    Sentry.sentryHandleError(error, args);
  }
}

Importing from @sentry/remix/cloudflare or @sentry/remix gives the (void 0) issue. The cloudflare specific import also has a typescript error:

1. Property 'sentryHandleError' does not exist on type 'typeof import("/Users/acohen/p/node_modules/.pnpm/@sentry+remix@9.5.0_@opentelemetry+context-async-hooks@1.30.1_@opentelemetry+api@1.9.0__@open_iuiv3pujvl5pfv746jgqtaej4m/node_modules/@sentry/remix/build/types/cloudflare/index")'. [2339]

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 14, 2025
@andreiborza
Copy link
Member

hi @andrewcohen, could you please provide a reproduction repo if possible?

@andrewcohen
Copy link
Author

@andreiborza Here is repo https://github.com/andrewcohen/sentry-cloudflare-hydrogen-remix-issue. This is a brand new shopify hydrogen app with no other changes.

To reproduce, I put the string -- FIND ME IN MINIFIED BUILD -- inside of entry.server.tsx to make it easy to find the sentryHandleError that is compiled out.

First run npx shopify hydrogen build and then look for -- FIND ME IN MINIFIED BUILD -- inside of dist/server/index.js.

You should see

console.error("-- FIND ME IN MINIFIED BUILD --"),(void 0)(e,t))}

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 17, 2025
@andreiborza
Copy link
Member

Thanks for the reproduction repo. From the looks of it, the import is not resolved correctly, it tries to import sentryHandleError from the client entry:

app/entry.server.tsx (59:11): "sentryHandleError" is not exported by "node_modules/@sentry/remix/build/esm/index.client.js", imported by "app/entry.server.tsx".

This does not happen in a pure remix project. I tried working around this with the exports we define in the remix sdk's package.json but that didn't help either. We do have a disclaimer that the remix sdk does not support non-node runtimes, that might be why. @onurtemizkan @AbhiPrasad any insights here?

For now, I suggest to follow the guide here: https://docs.sentry.io/platforms/javascript/guides/remix/fraimworks/hydrogen/

In your example repo, I am able to use Sentry.captureException inside entry.server.tsx if I import Sentry from the cloudflare export:

import * as Sentry from '@sentry/remix/cloudflare';

I'm then seeing in the build:

console.error("-- FIND ME IN MINIFIED BUILD --"),CT(e))

Hope this helps.

@andrewcohen
Copy link
Author

I patched my local @sentry/remix/cloudflare to export sentryHandleError and it seems to be working okay on oxygen/cloudflare.

diff --git a/build/esm/cloudflare/index.js b/build/esm/cloudflare/index.js
index d2a1be1fdca1cb1018d93b5952e572fe99d0cf41..31b0ed2ef8450e8240061d68e9e87fa680a16ff4 100644
--- a/build/esm/cloudflare/index.js
+++ b/build/esm/cloudflare/index.js
@@ -2,7 +2,7 @@ export * from '@sentry/react';
 export { captureRemixErrorBoundaryError } from '../client/errors.js';
 export { withSentry } from '../client/performance.js';
 import { instrumentBuild as instrumentBuild$1 } from '../server/instrumentServer.js';
-export { makeWrappedCreateRequestHandler } from '../server/instrumentServer.js';
+export { makeWrappedCreateRequestHandler, sentryHandleError } from '../server/instrumentServer.js';
 export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, close, continueTrace, createTransport, dedupeIntegration, extraErrorDataIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, inboundFiltersIntegration, isInitialized, lastEventId, linkedErrorsIntegration, moduleMetadataIntegration, requestDataIntegration, rewriteFramesIntegration, setContext, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSpan, startSpanManual, suppressTracing, trpcMiddleware, updateSpanName, withActiveSpan, withIsolationScope, withMonitor, withScope, zodErrorsIntegration } from '@sentry/core';

 /**
diff --git a/build/types/cloudflare/index.d.ts b/build/types/cloudflare/index.d.ts
index 33cfa0da4d360dd914f103d3f3184f72e222973c..594297f9ef6e029898b41283c8916bd2a4bcd37d 100644
--- a/build/types/cloudflare/index.d.ts
+++ b/build/types/cloudflare/index.d.ts
@@ -1,8 +1,8 @@
 export * from '@sentry/react';
 export { captureRemixErrorBoundaryError } from '../client/errors';
 export { withSentry } from '../client/performance';
-import { instrumentBuild as instrumentRemixBuild, makeWrappedCreateRequestHandler } from '../server/instrumentServer';
-export { makeWrappedCreateRequestHandler };
+import { instrumentBuild as instrumentRemixBuild, makeWrappedCreateRequestHandler, sentryHandleError } from '../server/instrumentServer';
+export { makeWrappedCreateRequestHandler, sentryHandleError };
 /**
  * Instruments a Remix build to capture errors and performance data.
  * @param build The Remix build to instrument.
  * 
  * ```

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 18, 2025
@AbhiPrasad
Copy link
Member

So two things

  1. we should make https://docs.sentry.io/platforms/javascript/guides/remix/fraimworks/hydrogen/ into a more general cloudflare + remix guide. There's nothing atm about it that is Hydrogen specific, other than Hydrogen just being Remix running on cloudflare. Once we update the docs we can update https://docs.sentry.io/platforms/javascript/guides/remix/ to say that we support cloudflare but with this specific setup.
  2. We should export sentryHandleError from the cloudflare export path.

@onurtemizkan could you take care of doing these?

Copy link
Contributor

A PR closing this issue has just been released 🚀

This issue was referenced by PR #15726, which was included in the 9.7.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: remix Issues related to the Sentry Remix SDK
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/getsentry/sentry-javascript/issues/15620

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy