Title: `@sentry/nextjs` throws `withSentry is not a function` · Issue #3750 · getsentry/sentry-javascript · GitHub
Open Graph Title: `@sentry/nextjs` throws `withSentry is not a function` · Issue #3750 · getsentry/sentry-javascript
X Title: `@sentry/nextjs` throws `withSentry is not a function` · Issue #3750 · getsentry/sentry-javascript
Description: Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javascript/releases Provide a link to the aff...
Open Graph Description: Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javas...
X Description: Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javas...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/3750
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@sentry/nextjs` throws `withSentry is not a function`","articleBody":"\u003c!-- Requirements: please go through this checklist before opening a new issue -->\r\n\r\n- [x] Review the documentation: https://docs.sentry.io/\r\n- [x] Search for existing issues: https://github.com/getsentry/sentry-javascript/issues\r\n- [x] Use the latest release: https://github.com/getsentry/sentry-javascript/releases\r\n- [ ] Provide a link to the affected event from your Sentry account\r\n\r\n## Package + Version\r\n\r\n- [ ] `@sentry/browser`\r\n- [ ] `@sentry/node`\r\n- [ ] `raven-js`\r\n- [ ] `raven-node` _(raven for node)_\r\n- [x] other: @sentry/nextjs\r\n\r\n### Version:\r\n\r\n```\r\n0.0.0\r\n```\r\n\r\n## Description\r\n\r\nUsing `Sentry.withSentry` fails using `\"@sentry/nextjs\": \"6.7.2\"`, I tried other versions, but the results were the same.\r\n\r\nSource code is open source and available at https://github.com/UnlyEd/next-right-now/pull/370.\r\n\r\n**Reproduction**: \r\n- `git clone git@github.com:UnlyEd/next-right-now.git nrn-next-sentry && cd nrn-next-sentry && git checkout next-sentry && cp .env.local.example .env.local && yarn && yarn start`\r\n- Open http://localhost:8888\r\n\r\n\r\n\r\n```ts\r\nimport { logEvent } from '@/modules/core/amplitude/amplitudeServerClient';\r\nimport {\r\n AMPLITUDE_API_ENDPOINTS,\r\n AMPLITUDE_EVENTS,\r\n} from '@/modules/core/amplitude/events';\r\nimport { filterExternalAbsoluteUrl } from '@/modules/core/js/url';\r\nimport { createLogger } from '@/modules/core/logging/logger';\r\nimport { configureReq } from '@/modules/core/sentry/server';\r\nimport { flushSafe } from '@/modules/core/sentry/universal';\r\nimport * as Sentry from '@sentry/nextjs';\r\nimport appendQueryParameter from 'append-query';\r\nimport {\r\n NextApiRequest,\r\n NextApiResponse,\r\n} from 'next';\r\n\r\nconst fileLabel = 'api/preview';\r\nconst logger = createLogger({\r\n fileLabel,\r\n});\r\n\r\n/**\r\n * Key to use in order to force disable \"auto preview mode\".\r\n *\r\n * If a page is loaded with noAutoPreviewMode=true in query parameter, then it won't try to enable the Preview mode, even if it's disabled.\r\n *\r\n * @example ?noAutoPreviewMode=true\r\n */\r\nexport const NO_AUTO_PREVIEW_MODE_KEY = 'noAutoPreviewMode';\r\n\r\ntype EndpointRequestQuery = {\r\n /**\r\n * Whether to start/stop the Preview Mode.\r\n *\r\n * @example ?stop=true Will stop the preview mode.\r\n * @example ?stop=false Will start the preview mode.\r\n * @default ?stop=false\r\n */\r\n stop: string;\r\n\r\n /**\r\n * Url to redirect to once the preview mode has been started/stopped.\r\n *\r\n * @example ?redirectTo=/en\r\n * @example ?redirectTo=/fr/solutions\r\n * @default ?redirectTo=/\r\n */\r\n redirectTo: string;\r\n}\r\n\r\ntype EndpointRequest = NextApiRequest & {\r\n query: EndpointRequestQuery;\r\n};\r\n\r\n/**\r\n * Preview Mode API.\r\n *\r\n * Enables and disables preview mode.\r\n *\r\n * The official example uses a security token to enable the preview mode, we don't.\r\n * This is a choice, as we don't need/want to protect our preview mode.\r\n * Protecting the preview mode makes most sense when this mode can be used in production, so that you can preview content served by Next.js from a CMS/tool of your choice.\r\n * Thus, it's strongly related to how you're planning on using it, and we decided to keep it simpler, by not using any kind of security.\r\n *\r\n * @param req\r\n * @param res\r\n * @method GET\r\n *\r\n * @see https://nextjs.org/docs/advanced-features/preview-mode#step-1-create-and-access-a-preview-api-route\r\n * @see https://nextjs.org/docs/advanced-features/preview-mode#clear-the-preview-mode-cookies\r\n */\r\nexport const preview = async (req: EndpointRequest, res: NextApiResponse): Promise\u003cvoid> => {\r\n try {\r\n configureReq(req, { fileLabel });\r\n\r\n await logEvent(AMPLITUDE_EVENTS.API_INVOKED, null, {\r\n apiEndpoint: AMPLITUDE_API_ENDPOINTS.PREVIEW,\r\n });\r\n\r\n const {\r\n stop = 'false',\r\n redirectTo = '/',\r\n }: EndpointRequestQuery = req.query;\r\n // Add NO_AUTO_PREVIEW_MODE_KEY parameter to query, to avoid running into infinite loops if the Preview mode couldn't start\r\n // Useful when the cookie created by Next.js cannot be written (Incognito mode)\r\n const safeRedirectUrl = appendQueryParameter(filterExternalAbsoluteUrl(redirectTo as string), `${NO_AUTO_PREVIEW_MODE_KEY}=true`);\r\n\r\n // XXX We don't want to enable preview mode for the production stage, it's only allowed for non-production stages\r\n // It's allowed during development for testing purpose\r\n // It's allowed during staging because this stage is being used as a \"preview environment\"\r\n if (process.env.NEXT_PUBLIC_APP_STAGE !== 'production') {\r\n if (stop === 'true') {\r\n res.clearPreviewData();\r\n\r\n logger.info('Preview mode stopped');\r\n } else {\r\n res.setPreviewData({});\r\n\r\n logger.info('Preview mode enabled');\r\n }\r\n } else {\r\n logger.error('Preview mode is not allowed in production');\r\n Sentry.captureMessage('Preview mode is not allowed in production', Sentry.Severity.Warning);\r\n }\r\n\r\n await flushSafe();\r\n\r\n res.writeHead(307, { Location: safeRedirectUrl });\r\n res.end();\r\n } catch (e) {\r\n Sentry.captureException(e);\r\n logger.error(e.message);\r\n\r\n await flushSafe();\r\n\r\n res.json({\r\n error: true,\r\n message: process.env.NEXT_PUBLIC_APP_STAGE === 'production' ? undefined : e.message,\r\n });\r\n }\r\n};\r\n\r\nexport default Sentry.withSentry(preview);\r\n\r\n```","author":{"url":"https://github.com/Vadorequest","@type":"Person","name":"Vadorequest"},"datePublished":"2021-06-25T09:55:58Z","url":"https://github.com/getsentry/sentry-javascript/issues/3750"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ee7764cd-2f4e-fa16-72dd-88d673bec684 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D094:F4D72:524BA6:701DCA:6B043F13 |
| html-safe-nonce | 3a616b5d24d2ff25cbe05ee1b51770370db510d2db147eee104ec8190fea23bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDk0OkY0RDcyOjUyNEJBNjo3MDFEQ0E6NkIwNDNGMTMiLCJ2aXNpdG9yX2lkIjoiNzU1ODU2NzUzNTYxMzA2NzAyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dbd707b4fa6031e0f4dccb210efc4e5806cf6db7742b82fbcca0b6d65e84339b |
| hovercard-subject-tag | issue:930024669 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/3750/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bfb7a0bad79cc233913613362a28955973b5ac733e28627824bc79769b0249e6/getsentry/sentry-javascript/issues/3750 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bfb7a0bad79cc233913613362a28955973b5ac733e28627824bc79769b0249e6/getsentry/sentry-javascript/issues/3750 |
| og:image:alt | Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javas... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Vadorequest |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 06dc448a76fe4751ac1db26524aefa3aa3e889a8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width