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

Error to render page on NextJs 12 with fallback = true #4090

Closed
4 tasks done
Leocardoso94 opened this issue Oct 26, 2021 · 18 comments · Fixed by #4276
Closed
4 tasks done

Error to render page on NextJs 12 with fallback = true #4090

Leocardoso94 opened this issue Oct 26, 2021 · 18 comments · Fixed by #4276
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@Leocardoso94
Copy link

Leocardoso94 commented Oct 26, 2021

Package + Version

  • @sentry/nextjs

Version:

6.13.3

Description

This error is happening on Vercel when building a page with fallback = true

Example file:
page/test/[foo].tsx

import { useRouter } from 'next/router';

interface Props {
  foo: string;
}

const Page = ({foo}: Props) => {
  const router = useRouter();

  if (!router.isFallback) return 'loading';

  return <div>{foo}</div>;
};

export const getStaticProps: GetStaticProps<Props> = async () => ({
  props: {
    foo: 'bar',
  },
});

export const getStaticPaths: GetStaticPaths = async () => ({
  paths: [],
  fallback: true,
});

export default Page;

Stacktrace:

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/api-utils.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:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/var/task/node_modules/@sentry/tracing/dist/index.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887: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/api-utils.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ]
}
2021-10-26T19:04:54.319Z	02403834-2c2d-4a70-a204-75908b39ab0c	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/_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/api-utils.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:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/var/task/node_modules/@sentry/tracing/dist/index.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887: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/api-utils.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ],
  page: '/teste/121'
}
RequestId: 02403834-2c2d-4a70-a204-75908b39ab0c Error: Runtime exited with error: exit status 1
Runtime.ExitError
@dwest-teo
Copy link

dwest-teo commented Oct 26, 2021

This issue is also impacting Vercel deployments with Next.js API routes wrapped in withSentry. The Next.js team appears to have located the problem in this issue. Apparently the error is caused by importing the entire next module in @sentry/nextjs/dist/utils/instrumentServer.js

@nicholasgriffintn
Copy link

Yeah, the problem line is here: https://github.com/getsentry/sentry-javascript/blob/master/packages/nextjs/src/utils/instrumentServer.ts#L13

@rodilo
Copy link

rodilo commented Oct 26, 2021

Can confirm it. Pages with getServerSideProps don't work because of this.

@ThePaulMcBride
Copy link

Found the same issue. API endpoints or pages using Sentry do not work in Next v12. They return 500 errors.

@adikari
Copy link

adikari commented Oct 28, 2021

I am having the same problem. any updates on the fix?

@lobsterkatie
Copy link
Member

lobsterkatie commented Oct 29, 2021

Hey, all.

First, sorry you're having trouble.

Second, Next 12 changes a lot of things, and given how new it is, we haven't yet had a chance to test all the different scenarios to find out exactly what in the SDK continues to work and what might need changing (or to then make those updates). Though we are working towards compatibility with Next 12, for now we're not guaranteeing compatibility with anything higher than Next 11.

Third, as to this issue...

The Next.js team appears to have located the problem in this issue. Apparently the error is caused by importing the entire next module in @sentry/nextjs/dist/utils/instrumentServer.js

Yeah, the problem line is here: https://github.com/getsentry/sentry-javascript/blob/master/packages/nextjs/src/utils/instrumentServer.ts#L13

It does seem that line may be causing a runtime issue, but I believe that's separate from this buildtime issue. If you look at the OP's stacktrace, it points to this line, from @sentry/tracing:

import { BrowserTracing } from './browser';
.

I think the problem is here:

// In webpack 5, you can get webpack to replace any module you'd like with an empty object, just by setting its
// `resolve.alias` value to `false`. Not much of our code is neatly separated into "things node needs" and "things
// the browser needs," but where it is, we can save ~1.6 kb in eventual bundle size by excluding code we know we
// don't need. (Normally this would only matter for the client side, but because vercel turns backend code into
// serverless functions, it's worthwhile to do it for both.)
if (buildContext.webpack.version.startsWith('5')) {
const excludedTracingDir = buildContext.isServer ? 'browser' : 'integrations/node';
newConfig.resolve = {
...newConfig.resolve,
alias: {
...newConfig.resolve?.alias,
[path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/esm/${excludedTracingDir}`)]: false,
// TODO It's not clear if it will ever pull from `dist` (in testing it never does), so we may not need this.
[path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/dist/${excludedTracingDir}`)]: false,
},
};
}
though I'm not yet sure exactly what's happening, and how fallback: true plays into it.

I'm away from my work computer at the moment, but once I get back I will see if removing that fixes the issue. It's there as a way to slightly decrease bundle size, but the savings isn't huge, so I'm happy to disable it for Next 12 if that fixes this issue.

@kevva
Copy link

kevva commented Oct 29, 2021

Try this if you're having MODULE_NOT_FOUND issues vercel/next.js#30561 (comment).

@Leocardoso94
Copy link
Author

Try this if you're having MODULE_NOT_FOUND issues vercel/next.js#30561 (comment).

After trying this, it works like a charm

@mataspetrikas
Copy link

Pls keep in mind that the setting of output file tracing to false is only a temporary measure.
This issue will have to be checked by the Sentry team if we want to have the fast deployments that Next12 is bringing.

@shivashp
Copy link

shivashp commented Nov 4, 2021

+1

@adikari
Copy link

adikari commented Nov 16, 2021

@lobsterkatie any updates on this? Been following the other thread on next as well. Seems like this is really setting us back vercel/next.js#30561 (comment)

@neverether
Copy link

@lobsterkatie any updates on this? Been following the other thread on next as well. Seems like this is really setting us back vercel/next.js#30561 (comment)

As referenced as this comment: #4103 (comment) in a related issue it looks like a PR has been merged with a fix #4027 a few hours ago. Looking at the changelog updates, looks like it's slated for release w/6.15.

@DavidChouinard
Copy link
Contributor

@Leocardoso94 can you confirm this issue has been resolved with 6.15?

@Leocardoso94
Copy link
Author

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

 /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/api-utils.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:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/var/task/node_modules/@sentry/tracing/dist/index.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887: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/api-utils.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ]
}
2021-11-17T15:33:58.695Z	978f68a0-36c3-482a-88fe-30ab1fab9a17	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/_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/api-utils.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:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/var/task/node_modules/@sentry/tracing/dist/index.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887: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/api-utils.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ],
  page: '/blog/melhor-tag-pedagio'
}
RequestId: 978f68a0-36c3-482a-88fe-30ab1fab9a17 Error: Runtime exited with error: exit status 1
Runtime.ExitError

😢

@smeubank smeubank added this to the Next.js 12 Support milestone Nov 18, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2021

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@iker-barriocanal
Copy link
Contributor

Hello everyone,

We have made a change that fixes some issues with the Next.js server when deployed on Vercel. These are available in the latest release, v6.16.1. Could you try this new version and provide any feedback?

Thanks!

@rodilo
Copy link

rodilo commented Dec 10, 2021

Hello everyone,

We have made a change that fixes some issues with the Next.js server when deployed on Vercel. These are available in the latest release, v6.16.1. Could you try this new version and provide any feedback?

Thanks!

Can confirm that it works ok now, next version 12.0.4.
Great work 👍

@iker-barriocanal
Copy link
Contributor

Glad to see the patch worked! I'm closing the issue, if someone runs into this problem, post an update and I'll reopen it. Thanks!

lobsterkatie added a commit that referenced this issue Dec 14, 2021
In #3978, code was introduced to prevent node tracing integrations (mongo, postgres, etc) from appearing in the browser bundle where they don't belong. However, as part of our larger push to make our code more treeshakable, we recently changed how we export those integrations[1], making the previous workaround unnecessary.

As a bonus, this should fix a rendering issue some users were having when using the `fallback` flag.

Tested locally and on vercel.

Fixes #4090.

[1] #4204
onurtemizkan pushed a commit that referenced this issue Dec 19, 2021
In #3978, code was introduced to prevent node tracing integrations (mongo, postgres, etc) from appearing in the browser bundle where they don't belong. However, as part of our larger push to make our code more treeshakable, we recently changed how we export those integrations[1], making the previous workaround unnecessary.

As a bonus, this should fix a rendering issue some users were having when using the `fallback` flag.

Tested locally and on vercel.

Fixes #4090.

[1] #4204
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 Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.