You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't use withSentryConfig because it breaks NextJS #9450
Hi, thanks for writing in. I am also using next auth in my sideproject in combination with the SDK and I cannot reproduce this. Would you mind sharing a small reproduction example (git repo we can clone or stackblitz or similar) so we an effectively debug this? Thanks!
@Deliaz Can you please open a separate issue with reproduction examples, as this does not seem to be the same error as described in the original issue. Thanks!
Hello, sorry guys, I updated next, next-auth and @sentry/nextjs to its latest version and error remain exactly the same: "@sentry/nextjs": "^7.78.0" "next": "^14.0.1" "next-auth": "^4.24.4"
warn - In order to be able to deminify errors, @sentry/nextjs creates sourcemaps and uploads them to the Sentry server. Depending on your deployment setup, this means your original code may be visible in browser devtools in production. To prevent this, set hideSourceMaps to true in the sentry options in your next.config.js. To disable this warning without changing sourcemap behavior, set hideSourceMaps to false. (In @sentry/nextjs version 8.0.0 and beyond, this option will default to true.) See https://webpack.js.org/configuration/devtool/ and https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map for more information.
✓ Ready in 3.4s
○ Compiling /login ...
✓ Compiled /login in 11.3s (794 modules)
⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
○ Compiling /api/auth/[...nextauth] ...
✓ Compiled /api/auth/[...nextauth] in 2.6s (848 modules)
⨯ TypeError: Cannot read properties of undefined (reading 'type')
at assertConfig (/app/node_modules/next-auth/core/lib/assert.js:69:18)
at AuthHandler (/app/node_modules/next-auth/core/index.js:77:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthApiHandler (/app/node_modules/next-auth/next/index.js:22:19)
at async NextAuth._args$ (/app/node_modules/next-auth/next/index.js:108:14)
at async /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:153:35 {
page: '/api/auth/[...nextauth]'
}
⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
⨯ TypeError: Cannot read properties of undefined (reading 'type')
at assertConfig (/app/node_modules/next-auth/core/lib/assert.js:69:18)
at AuthHandler (/app/node_modules/next-auth/core/index.js:77:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthApiHandler (/app/node_modules/next-auth/next/index.js:22:19)
at async NextAuth._args$ (/app/node_modules/next-auth/next/index.js:108:14)
at async /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:153:35 {
page: '/api/auth/[...nextauth]'
@lforst sorry I didn't paste the whole error, it is exactly the same.
I found out that on [...nextauth].js I'm importing each provider object on a different file, if I remove those imports the error is gone.
Something between that and withSentryConfig is producing the error, super hard to realise what is going on.
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error Unexpected token < in JSON at position 0 {
error: {
message: 'Unexpected token < in JSON at position 0',
stack: 'SyntaxError: Unexpected token < in JSON at position 0\n' +
' at JSON.parse (<anonymous>)\n' +
' at parseJSONFromBytes (node:internal/deps/undici/undici:4553:19)\n' +
' at successSteps (node:internal/deps/undici/undici:4527:27)\n' +
' at fullyReadBody (node:internal/deps/undici/undici:1307:9)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async specConsumeBody (node:internal/deps/undici/undici:4536:7)',
name: 'SyntaxError'
},
url: 'http://localhost:3001/api/auth/providers',
message: 'Unexpected token < in JSON at position 0'
}
Image with src "/images/gradient.svg" has legacy prop "layout". Did you forget to run the codemod?
Read more: https://nextjs.org/docs/messages/next-image-upgrade-to-13
Image with src "/images/gradient.svg" has legacy prop "objectFit". Did you forget to run the codemod?
Read more: https://nextjs.org/docs/messages/next-image-upgrade-to-13
⨯ TypeError: Cannot read properties of undefined (reading 'type')
at assertConfig (/app/node_modules/next-auth/core/lib/assert.js:69:18)
at AuthHandler (/app/node_modules/next-auth/core/index.js:77:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthApiHandler (/app/node_modules/next-auth/next/index.js:22:19)
at async NextAuth._args$ (/app/node_modules/next-auth/next/index.js:108:14)
at async /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:153:35 {
page: '/api/auth/[...nextauth]'
}
@leonardopiperai Ok this is a bit unlucky but also kinda an inaccuracy on your part. Every file you put under /pages/api will be turned into an API route - and Sentry will auto wrap all api routes. In your case you put your credentialProviders under the /pages/api/auth/providers folder which is gonna end up as an API route. You very likely do not want this and you should put that file somewhere else in your project. You can verify this by looking at the Next.js build output:
Route (pages) Size First Load JS
┌ ○ / 417 B 88.8 kB
├ └ css/e7d3bab42d9af29d.css 613 B
├ /_app 0 B 88.4 kB
├ ○ /404 182 B 88.5 kB
├ λ /api/auth/[...nextauth] 0 B 88.4 kB
├ λ /api/auth/providers/credentialProviders 0 B 88.4 kB <<----- This one
├ λ /api/hello 0 B 88.4 kB
├ λ /api/sentry-example-api 0 B 88.4 kB
└ ○ /sentry-example-page 6.73 kB 95.1 kB
+ First Load JS shared by all 88.4 kB
├ chunks/framework-66d32731bdd20e83.js 45.2 kB
├ chunks/main-8c2fcf961f1eeec3.js 31.8 kB
├ chunks/pages/_app-a96ccf5c4ceb0abb.js 10.4 kB
└ chunks/webpack-94547de1949c56d7.js 950 B
ƒ Middleware 61.3 kB
○ (Static) prerendered as static content
λ (Dynamic) server-rendered on demand using Node.js
It is very unlikely that we can or will fix this, since it is mostly due to user error.
@lforst Okey.. I see, yes, this looks like an unfortunate mix between a bad auth config and withSentryConfig wrapper. I'm going to keep trying to integrate Sentry by fixing the next auth.
Thanks man for taking a look into!
Activity
lforst commentedon Nov 3, 2023
Hi, thanks for writing in. I am also using next auth in my sideproject in combination with the SDK and I cannot reproduce this. Would you mind sharing a small reproduction example (git repo we can clone or stackblitz or similar) so we an effectively debug this? Thanks!
Deliaz commentedon Nov 4, 2023
Getting the same problem with Next v14 and Sentry SDK 7.77.0:
lforst commentedon Nov 4, 2023
@Deliaz Can you please open a separate issue with reproduction examples, as this does not seem to be the same error as described in the original issue. Thanks!
37 remaining items
leonardopiperai commentedon Nov 6, 2023
Thanks guys! @lforst let us know if you have any update on the fix.
Lms24 commentedon Nov 8, 2023
The fix was released in version 7.78.0.
leonardopiperai commentedon Nov 9, 2023
Hello, sorry guys, I updated next, next-auth and @sentry/nextjs to its latest version and error remain exactly the same:
"@sentry/nextjs": "^7.78.0"
"next": "^14.0.1"
"next-auth": "^4.24.4"
next dev -p ${PORT:=3001}
▲ Next.js 14.0.1
warn - In order to be able to deminify errors, @sentry/nextjs creates sourcemaps and uploads them to the Sentry server. Depending on your deployment setup, this means your original code may be visible in browser devtools in production. To prevent this, set hideSourceMaps to true in the sentry options in your next.config.js. To disable this warning without changing sourcemap behavior, set hideSourceMaps to false. (In @sentry/nextjs version 8.0.0 and beyond, this option will default to true.) See https://webpack.js.org/configuration/devtool/ and https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map for more information.
✓ Ready in 3.4s
○ Compiling /login ...
✓ Compiled /login in 11.3s (794 modules)
⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
○ Compiling /api/auth/[...nextauth] ...
✓ Compiled /api/auth/[...nextauth] in 2.6s (848 modules)
⨯ TypeError: Cannot read properties of undefined (reading 'type')
at assertConfig (/app/node_modules/next-auth/core/lib/assert.js:69:18)
at AuthHandler (/app/node_modules/next-auth/core/index.js:77:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthApiHandler (/app/node_modules/next-auth/next/index.js:22:19)
at async NextAuth._args$ (/app/node_modules/next-auth/next/index.js:108:14)
at async /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:153:35 {
page: '/api/auth/[...nextauth]'
}
⚠ Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload
⨯ TypeError: Cannot read properties of undefined (reading 'type')
at assertConfig (/app/node_modules/next-auth/core/lib/assert.js:69:18)
at AuthHandler (/app/node_modules/next-auth/core/index.js:77:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthApiHandler (/app/node_modules/next-auth/next/index.js:22:19)
at async NextAuth._args$ (/app/node_modules/next-auth/next/index.js:108:14)
at async /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:153:35 {
page: '/api/auth/[...nextauth]'
lforst commentedon Nov 9, 2023
@leonardopiperai These errors don't look the same. Can you please open a new issue and provide reproduction? Thanks!
leonardopiperai commentedon Nov 9, 2023
@lforst sorry I didn't paste the whole error, it is exactly the same.
I found out that on [...nextauth].js I'm importing each provider object on a different file, if I remove those imports the error is gone.
Something between that and withSentryConfig is producing the error, super hard to realise what is going on.
[...nextauth].js
hubspotProvider.js
error:
lforst commentedon Nov 9, 2023
@leonardopiperai Please provide a small reproduction example we can run locally to reproduce this error. Thanks!
leonardopiperai commentedon Nov 12, 2023
@lforst Sure, I invited you to a repo where the issue is reproducible.
Thanks!
lforst commentedon Nov 13, 2023
@leonardopiperai Ok this is a bit unlucky but also kinda an inaccuracy on your part. Every file you put under
/pages/apiwill be turned into an API route - and Sentry will auto wrap all api routes. In your case you put yourcredentialProvidersunder the/pages/api/auth/providersfolder which is gonna end up as an API route. You very likely do not want this and you should put that file somewhere else in your project. You can verify this by looking at the Next.js build output:It is very unlikely that we can or will fix this, since it is mostly due to user error.
leonardopiperai commentedon Nov 13, 2023
@lforst Okey.. I see, yes, this looks like an unfortunate mix between a bad auth config and withSentryConfig wrapper. I'm going to keep trying to integrate Sentry by fixing the next auth.
Thanks man for taking a look into!