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

next export fails when having _error and 404 page #6088

Closed
3 tasks done
bas080 opened this issue Oct 29, 2022 · 5 comments · Fixed by #6682
Closed
3 tasks done

next export fails when having _error and 404 page #6088

bas080 opened this issue Oct 29, 2022 · 5 comments · Fixed by #6682

Comments

@bas080
Copy link

bas080 commented Oct 29, 2022

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.17.2

Framework Version

13.0.0

Link to Sentry event

No response

Steps to Reproduce

Versions

jq .version  < ./node_modules/next/package.json
jq .version  < ./node_modules/@sentry/nextjs/package.json
"13.0.0"
"7.17.2"

Reproduce

npm run build && npm run export

> localu@0.0.1 build
> next build

warn  - You have enabled experimental feature (cpus) in next.config.mjs.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

info  - Linting and checking validity of types...
info  - Creating an optimized production build...
info  - Compiled successfully
info  - Collecting page data...
info  - Generating static pages (0/53)
info  - Generating static pages (13/53)
info  - Generating static pages (26/53)
info  - Generating static pages (39/53)
info  - Generating static pages (53/53)
info  - Finalizing page optimization...

Route (pages)                                         Size     First Load JS
┌   /_app                                             0 B             109 kB
├ ● /[language]/[webpage] (ISR: 1 Seconds) (8775 ms)  13.7 kB         128 kB
├   ├ /ru/404 (334 ms)
├   ├ /en/index
├   ├ /he/index
├   ├ /ru/index
├   ├ /en/boat-hire
├   ├ /he/boat-hire
├   ├ /ru/boat-hire
├   └ [+44 more paths]
├ λ /404                                              438 B           109 kB
├ λ /api/[sheet]/[gid]/invalidate                     0 B             109 kB
├ λ /api/[sheet]/[gid]/json                           0 B             109 kB
├ λ /api/email/[language]/[webpage]                   0 B             109 kB
├ λ /api/email/[language]/[webpage]/send              0 B             109 kB
├ λ /api/form/[language]/[webpage]                    0 B             109 kB
├ λ /api/ping                                         0 B             109 kB
├ λ /api/publish                                      0 B             109 kB
├ ● /public/robots.txt                                541 B           115 kB
└ ● /public/sitemap.xml (2449 ms)                     543 B           115 kB
+ First Load JS shared by all                         114 kB
  ├ chunks/framework-3b5a00d5d7e8d93b.js              45.4 kB
  ├ chunks/main-109639d04b48b523.js                   29.4 kB
  ├ chunks/pages/_app-8141b332980f9e18.js             32.1 kB
  ├ chunks/webpack-32ca610b9890a2c4.js                1.81 kB
  └ css/77ad3477c6267d74.css                          5.55 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
   (ISR)     incremental static regeneration (uses revalidate in getStaticProps)


> localu@0.0.1 export
> next export --threads 1

warn  - You have enabled experimental feature (cpus) in next.config.mjs.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

info  - using build directory: /home/ant/projects/localu/.next
warn  - rewrites, redirects, and headers are not applied when exporting your application, detected (rewrites, redirects). See more info here: https://nextjs.org/docs/messages/export-no-custom-routes
info  - Copying "static build" directory
info  - No "exportPathMap" found in "/home/ant/projects/localu/next.config.mjs". Generating map from "./pages"
info  - Launching 1 workers
warn  - Statically exporting a Next.js application via `next export` disables API routes.
This command is meant for static-only hosts, and is not necessary to make your application static.
Pages in your application without server-side data dependencies will be automatically statically exported by `next build`, including pages powered by `getStaticProps`.
Learn more: https://nextjs.org/docs/messages/api-routes-static-export
info  - Exporting (0/4)
info  - Copying "public" directory
info  - Exporting (1/4)
info  - Exporting (2/4)
warn  - Detected getInitialProps on page '/_error' while running "next export". It's recommended to use getStaticProps which has a more correct behavior for static exporting.
Read more: https://nextjs.org/docs/messages/get-initial-props-export

Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading '__sentry_original__')
    at Object.autoEndTransactionOnResponseEnd (/home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/utils/responseEnd.js:34:19)
    at /home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:92:19
    at bound (node:domain:433:15)
    at runBound (node:domain:444:12)
    at Object.callTracedServerSideDataFetcher (/home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:128:5)
    at Function.getInitialProps (/home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryServerSideErrorGetInitialProps.js:38:23)
    at /home/ant/projects/localu/node_modules/next/dist/shared/lib/utils.js:84:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/ant/projects/localu/node_modules/@swc/helpers/lib/_async_to_generator.js:23:28)
    at _next (/home/ant/projects/localu/node_modules/@swc/helpers/lib/_async_to_generator.js:12:17)
info  - Exporting (3/4)
warn  - Detected getInitialProps on page '/_error' while running "next export". It's recommended to use getStaticProps which has a more correct behavior for static exporting.
Read more: https://nextjs.org/docs/messages/get-initial-props-export

Error occurred prerendering page "/404.html". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading '__sentry_original__')
    at Object.autoEndTransactionOnResponseEnd (/home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/utils/responseEnd.js:34:19)
    at /home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:92:19
    at bound (node:domain:433:15)
    at runBound (node:domain:444:12)
    at Object.callTracedServerSideDataFetcher (/home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:128:5)
    at Function.getInitialProps (/home/ant/projects/localu/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryServerSideErrorGetInitialProps.js:38:23)
    at /home/ant/projects/localu/node_modules/next/dist/shared/lib/utils.js:84:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/ant/projects/localu/node_modules/@swc/helpers/lib/_async_to_generator.js:23:28)
    at _next (/home/ant/projects/localu/node_modules/@swc/helpers/lib/_async_to_generator.js:12:17)
info  - Exporting (4/4)
Error: Export encountered errors on following paths:
	/_error: /404
	/_error: /404.html
    at /home/ant/projects/localu/node_modules/next/dist/export/index.js:405:19
    at async Span.traceAsyncFn (/home/ant/projects/localu/node_modules/next/dist/trace/trace.js:79:20)

Notice that the export fails.

Expected Result

That all pages are built

Actual Result

It errors for the _error page.

@bas080
Copy link
Author

bas080 commented Oct 29, 2022

I get the same error with nextjs version "12.3.1"

@bas080
Copy link
Author

bas080 commented Oct 29, 2022

Last version of sentry/nextjs that I used and worked was "7.13.0".

@lforst
Copy link
Member

lforst commented Oct 31, 2022

Hi, thanks for reporting this!

I was able to reproduce this by running next build && next export while having a _error.js page alongside a 404.js page with our auto wrapping enabled.

For now, you can disable our auto instrumentation to get around the error when exporting by setting autoInstrumentServerFunctions: false.

Nonetheless, we should fix this so I am backlogging this.

@lforst lforst changed the title Export fails when using newer version of sentry/nextjs next export fails when having _error and 404 page Oct 31, 2022
@lforst lforst self-assigned this Jan 9, 2023
@lforst
Copy link
Member

lforst commented Jan 10, 2023

Hi, this should be fixed in release 7.30.0 of the SDK.

@mzruiz
Copy link

mzruiz commented Mar 26, 2023

Commenting so others can see this thread - took a few hours on Google to find.

I was using

  next: "13.2.0",
  react: "18.2.0",

and was receiving Cannot read properties of undefined (reading 'getInitialProps') after running yarn run build.

This issue in the nextjs repo was the closest issue I found to describe what was happening to me.

Ultimately, the recommendation above by @lforst solved it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants