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

Crash on server side running on Vercel after upgrading to Next.js 12 #4103

Closed
4 of 9 tasks
davguij opened this issue Oct 29, 2021 · 18 comments · Fixed by #4255
Closed
4 of 9 tasks

Crash on server side running on Vercel after upgrading to Next.js 12 #4103

davguij opened this issue Oct 29, 2021 · 18 comments · Fixed by #4255
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@davguij
Copy link

davguij commented Oct 29, 2021

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/nextjs

Version:

6.13.3

Description

After upgrading a project from Next 11.1.2 to 12.0.1, the Next.js-powered API endpoints start to crash, as in https://drafted-webapp-hmopbeh9f-davidguijarro.vercel.app/api/status.

Here's a sample log of the error:

[GET] /api/status
09:32:11:52
2021-10-29T07:32:12.548Z	1c5c0769-4fd8-4480-8b9a-08598598cd1f	ERROR	Error: Cannot find module './browser'
Require stack:
- /var/task/node_modules/@sentry/tracing/dist/index.js
- /var/task/node_modules/@sentry/node/dist/handlers.js
- /var/task/node_modules/@sentry/node/dist/index.js
- /var/task/node_modules/@sentry/nextjs/dist/index.server.js
- /var/task/.next/server/pages/api/status.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/___next_launcher.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/var/task/node_modules/@sentry/tracing/dist/index.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/node_modules/@sentry/tracing/dist/index.js',
    '/var/task/node_modules/@sentry/node/dist/handlers.js',
    '/var/task/node_modules/@sentry/node/dist/index.js',
    '/var/task/node_modules/@sentry/nextjs/dist/index.server.js',
    '/var/task/.next/server/pages/api/status.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ]
}
RequestId: 1c5c0769-4fd8-4480-8b9a-08598598cd1f Error: Runtime exited with error: exit status 1
Runtime.ExitError

Weird enough, this only happens when deployed to Vercel, not when running on local.

I also confirmed that completely removing Sentry from the project solves the issue.

@tonimasc
Copy link

Also happening to me

[GET] /_next/data/NfIMoVz8P-4n3aklepICZ/es/products/fresa-vendor-madrid.json
12:20:06:40
k/node_modules/@sentry/node/dist/handlers.js

  • /var/task/node_modules/@sentry/node/dist/index.js
  • /var/task/node_modules/@sentry/nextjs/dist/index.server.js
  • /var/task/.next/server/pages/_app.js
  • /var/task/node_modules/next/dist/server/require.js
  • /var/task/node_modules/next/dist/server/load-components.js
  • /var/task/node_modules/next/dist/server/next-server.js
  • /var/task/___next_launcher.js
  • /var/runtime/UserFunction.js
  • /var/runtime/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object. (/var/task/node_modules/@sentry/tracing/dist/index.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/var/task/node_modules/@sentry/tracing/dist/index.js',
    '/var/task/node_modules/@sentry/node/dist/handlers.js',
    '/var/task/node_modules/@sentry/node/dist/index.js',
    '/var/task/node_modules/@sentry/nextjs/dist/index.server.js',
    '/var/task/.next/server/pages/_app.js',
    '/var/task/node_modules/next/dist/server/require.js',
    '/var/task/node_modules/next/dist/server/load-components.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
    ]
    }

@atilafassina
Copy link

atilafassina commented Oct 29, 2021

Current workaround is to add
outputFileTracing: false to the root of your next.config.js

that will probably lead to larger artifact, but solves the issue.

output-file-tracing

@smeubank smeubank added the Package: nextjs Issues related to the Sentry Nextjs SDK label Nov 3, 2021
@sanderkooger
Copy link

sanderkooger commented Nov 5, 2021

Same issue here, Sentry breaks functionality of Vercel serverless functions, but they do run locally

Workarround worked:
outputFileTracing: false to the root of your next.config.js

@cezarneaga
Copy link

getting this too. will this issue track a proper fix?

@dcastil
Copy link

dcastil commented Nov 8, 2021

Edit: These are related to Sentry and Next.js but not to the issue discussed here. Sorry, I got that mixed up.

Yes there are two open PRs at the moment:

@DavidChouinard
Copy link
Contributor

@davguij #4027 got merged yesterday, can you verify if the issue still exists with Sentry 6.5.0? (cc. @cezarneaga, @sanderkooger)

@cezarneaga
Copy link

works for me. thanks a bunch!

@bnjmnt4n
Copy link
Contributor

bnjmnt4n commented Nov 17, 2021

I just upgraded to @sentry/[email protected] and [email protected]. This issue still occurs:

ERROR	Error: Cannot find module '/var/task/node_modules/next/dist/server/next.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:321:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:534:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/var/task/node_modules/@sentry/nextjs/dist/utils/instrumentServer.js:8:14)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32) {  code: 'MODULE_NOT_FOUND',  path: '/var/task/node_modules/next/package.json',  requestPath: 'next'}

I believe #4027 is a separate issue to this. A comment from the Next.js maintainer seems to indicate that this issue is caused by Sentry importing a reference to next, which is disallowed on Vercel since it would increase the bundle size. I'm not sure why it can't be tree-shaked (Seems like there isn't any additional bundling done, and the full module is imported). Since the instrumentServer function directly modifies internals in the Next.js server, it might be good to communicate directly with the Next.js team to figure out a solution, since this seems to be a major blocker to Sentry + Next.js adoption on Vercel.

The workaround of outputFileTracing is also not a feasible long-term solution, since it severely increases the bundle size of all Next.js pages (~1.6x in my case).

@davguij
Copy link
Author

davguij commented Nov 17, 2021

@DavidChouinard I tried upgrading to @sentry/[email protected] before upgrading Next, so that it's still at [email protected] but unfortunately the original error was still there.

Then I tried upgrading Next to 12.0.4 and the original error was gone, but I'm seeing the same issue as @bnjmnt4n posted.

@felixmeziere
Copy link

Still have the error with 6.15.0 :/

@Ryuurock
Copy link

+1

@IHIutch
Copy link

IHIutch commented Nov 18, 2021

Upgrading to 6.5.0 and setting outputFileTracing: false has worked for me

@sanderkooger
Copy link

@davguij #4027 got merged yesterday, can you verify if the issue still exists with Sentry 6.5.0? (cc. @cezarneaga, @sanderkooger)

Sure looks like it. We are starting to think to step off of sentry for a moment, until things are a bit more stable.

Disabling outputFileTracing does work. But we were looking through the history here and sentry seems to break prod quite often?

@IGUNUBLUE
Copy link

Current workaround is to add outputFileTracing: false to the root of your next.config.js

that will probably lead to larger artifact, but solves the issue.

output-file-tracing

const { withSentryConfig } = require('@sentry/nextjs')

const moduleExports = {
  outputFileTracing: false
}

const sentryWebpackPluginOptions = {
  silent: true, 
}
module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions)

Excuse me, could you please help me by indicating if this is the correct way?

@dcastil
Copy link

dcastil commented Nov 24, 2021

@IGUNUBLUE Yep, at least that is my current workaround.

@fungilation
Copy link

outputFileTracing: false does not work for me. And my crash condition is somewhat different, it crashes on SSR pages only.

What's odd to me is next build ; next start works on the same SSR pages that crash when only deployed on Vercel previews. Local dev build also works fine.

Would love to have @sentry/nextjs compatible with Next 12, as this is a pretty major blocker for Next + Sentry.

@gpichot
Copy link

gpichot commented May 12, 2022

Just adding a quick message as I stumbled on this error with using nx, sentry and next. I read too quickly the documentation and missed this part :

Make sure to add the Sentry config last; otherwise, the source maps the plugin receives may not be final.

If withSentryConfig is not the last function to applied, nextJS bundling will not work (Cannot find module '@sentry/nextjs'):

module.exports = withSentryConfig(withNx(baseOptions), {
  silent: true,
});

@bigsee
Copy link

bigsee commented Oct 10, 2022

Upgrading to 6.19.7 worked for me. I did not need to add outputFileTracing: false to my config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.