Title: Next.js v12 server side crashing on Vercel · Issue #4207 · getsentry/sentry-javascript · GitHub
Open Graph Title: Next.js v12 server side crashing on Vercel · Issue #4207 · getsentry/sentry-javascript
X Title: Next.js v12 server side crashing on Vercel · Issue #4207 · getsentry/sentry-javascript
Description: Related to #4103. The Next.js SDK crashes apps on the server-side when deployed on Vercel. It doesn't happen locally. Error logs 2021-12-01T13:01:48.296Z 31dc2972-71bb-4bcd-8ca1-d0d7502aa36c ERROR Error: Cannot find module '/var/task/nod...
Open Graph Description: Related to #4103. The Next.js SDK crashes apps on the server-side when deployed on Vercel. It doesn't happen locally. Error logs 2021-12-01T13:01:48.296Z 31dc2972-71bb-4bcd-8ca1-d0d7502aa36c ERROR ...
X Description: Related to #4103. The Next.js SDK crashes apps on the server-side when deployed on Vercel. It doesn't happen locally. Error logs 2021-12-01T13:01:48.296Z 31dc2972-71bb-4bcd-8ca1-d0d7502aa36c ER...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/4207
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Next.js v12 server side crashing on Vercel","articleBody":"Related to https://github.com/getsentry/sentry-javascript/issues/4103.\r\n\r\nThe Next.js SDK crashes apps on the server-side when deployed on Vercel. It doesn't happen locally.\r\n\r\n\u003cdetails>\r\n\u003csummary>Error logs\u003c/summary>\r\n\r\n```\r\n2021-12-01T13:01:48.296Z\t31dc2972-71bb-4bcd-8ca1-d0d7502aa36c\tERROR\tError: Cannot find module '/var/task/node_modules/next/dist/server/next.js'. Please verify that the package.json has a valid \"main\" entry\r\n at tryPackage (internal/modules/cjs/loader.js:321:19)\r\n at Function.Module._findPath (internal/modules/cjs/loader.js:534:18)\r\n at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)\r\n at Function.Module._load (internal/modules/cjs/loader.js:746:27)\r\n at Module.require (internal/modules/cjs/loader.js:974:19)\r\n at require (internal/modules/cjs/helpers.js:93:18)\r\n at Object.\u003canonymous> (/var/task/node_modules/@sentry/nextjs/dist/utils/instrumentServer.js:8:14)\r\n at Module._compile (internal/modules/cjs/loader.js:1085:14)\r\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)\r\n at Module.load (internal/modules/cjs/loader.js:950:32) {\r\n code: 'MODULE_NOT_FOUND',\r\n path: '/var/task/node_modules/next/package.json',\r\n requestPath: 'next'\r\n}\r\nRequestId: 31dc2972-71bb-4bcd-8ca1-d0d7502aa36c Error: Runtime exited with error: exit status 1\r\nRuntime.ExitError\r\n```\r\n\r\n\u003c/details>\r\n\r\n### Cause\r\n\r\nThis error is caused by importing modules from `next`. In the SDK, this import is required to instrument the server, see https://github.com/getsentry/sentry-javascript/blob/a6c384c935f9cd9ea7c9b5442537e08e3f13d1b7/packages/nextjs/src/utils/instrumentServer.ts#L14\r\n\r\nand the server instrumentation is run when initializing the SDK on the server side, see https://github.com/getsentry/sentry-javascript/blob/a6c384c935f9cd9ea7c9b5442537e08e3f13d1b7/packages/nextjs/src/index.server.ts#L122-L123\r\n\r\n### Solution\r\n\r\nOn Vercel, the server instrumentation has no effect. Errors and transactions are captured through the [custom `_error.js` page](https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-a-custom-_error-page) and the [`withSentry` handler](https://docs.sentry.io/platforms/javascript/guides/nextjs/#configure). Not instrumenting the server (to not import any modules from `next`) when an app is deployed on Vercel should fix the issue, and the [`VERCEL` environment variable](https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables) can be helpful here, as used in https://github.com/getsentry/sentry-javascript/blob/a6c384c935f9cd9ea7c9b5442537e08e3f13d1b7/packages/nextjs/src/index.server.ts#L57\r\n\r\nTechnical details may be more complex, to be defined.","author":{"url":"https://github.com/iker-barriocanal","@type":"Person","name":"iker-barriocanal"},"datePublished":"2021-12-01T13:22:45Z","url":"https://github.com/getsentry/sentry-javascript/issues/4207"}
| 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:9caccdbf-bb4a-b76e-5cdf-785a114c613a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B9A:27DDD:8EB9F:C1C85:6B0446AB |
| html-safe-nonce | 152219a2ead03b1a98b0213d876a11088ab19fef82c38abfbf3e547cb07ee80b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjlBOjI3REREOjhFQjlGOkMxQzg1OjZCMDQ0NkFCIiwidmlzaXRvcl9pZCI6IjQ5NDIwMDg3ODUyNzIzMjU4MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ebf505cb45263fbcace776dd7bb51123ccb9e671869165780e62bbcfb12029af |
| hovercard-subject-tag | issue:1068402951 |
| 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/4207/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c678148b6cfa3feb61ecdb64953a051120426f5e9055c8b790a6624d21007e33/getsentry/sentry-javascript/issues/4207 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c678148b6cfa3feb61ecdb64953a051120426f5e9055c8b790a6624d21007e33/getsentry/sentry-javascript/issues/4207 |
| og:image:alt | Related to #4103. The Next.js SDK crashes apps on the server-side when deployed on Vercel. It doesn't happen locally. Error logs 2021-12-01T13:01:48.296Z 31dc2972-71bb-4bcd-8ca1-d0d7502aa36c ERROR ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iker-barriocanal |
| hostname | github.com |
| expected-hostname | github.com |
| None | d4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46 |
| 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 | 9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77 |
| 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