Problem with utils within the API #9132
Closed
lucasantoniooficial
started this conversation in
General
Replies: 1 comment
-
@lucasantoniooficial sounds like a bug. Could you open a bug report issue and fill out the template? Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a NextJS 13 application, in which I use Sentry and I discovered today that if I try to use some utility, Sentry starts popping up a bunch of errors.
error - Error [TypeError]: resolver is not a function at /app/node_modules/next/dist/server/api-utils/node.js:392:16 at /app/node_modules/next/dist/server/lib/trace/tracer.js:108:36 at NoopContextManager.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057) at ContextAPI.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516) at NoopTracer.startActiveSpan (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086) at ProxyTracer.startActiveSpan (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847) at /app/node_modules/next/dist/server/lib/trace/tracer.js:97:107 at NoopContextManager.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057) at ContextAPI.with (/app/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516) at NextTracerImpl.trace (/app/node_modules/next/dist/server/lib/trace/tracer.js:97:32) at apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:390:63) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async DevServer.runApi (/app/node_modules/next/dist/server/next-server.js:668:9) at async Object.fn (/app/node_modules/next/dist/server/next-server.js:1118:35) at async Router.execute (/app/node_modules/next/dist/server/router.js:311:32) at async DevServer.runImpl (/app/node_modules/next/dist/server/base-server.js:599:29) at async DevServer.run (/app/node_modules/next/dist/server/dev/next-dev-server.js:922:20) at async DevServer.handleRequestImpl (/app/node_modules/next/dist/server/base-server.js:528:20) { digest: undefined } This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: TypeError: Cannot read properties of undefined (reading 'end') at Object.autoEndTransactionOnResponseEnd (/app/node_modules/@sentry/nextjs/cjs/common/utils/responseEnd.js:33:11) at /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:118:29 at /app/node_modules/@sentry/node/cjs/async/hooks.js:38:14 at AsyncLocalStorage.run (node:async_hooks:346:14) at Object.runWithAsyncContext (/app/node_modules/@sentry/node/cjs/async/hooks.js:37:25) at Object.runWithAsyncContext (/app/node_modules/@sentry/core/cjs/hub.js:527:36) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:58:33) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:25:61) at eval (webpack-internal:///(api)/./src/pages/api/auth/login.ts:25:114) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) error - unhandledRejection: Error [TypeError]: Cannot read properties of undefined (reading 'end') at Object.autoEndTransactionOnResponseEnd (/app/node_modules/@sentry/nextjs/cjs/common/utils/responseEnd.js:33:11) at /app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:118:29 at /app/node_modules/@sentry/node/cjs/async/hooks.js:38:14 at AsyncLocalStorage.run (node:async_hooks:346:14) at Object.runWithAsyncContext (/app/node_modules/@sentry/node/cjs/async/hooks.js:37:25) at Object.runWithAsyncContext (/app/node_modules/@sentry/core/cjs/hub.js:527:36) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:58:33) at Object.apply (/app/node_modules/@sentry/nextjs/cjs/common/wrapApiHandlerWithSentry.js:25:61) at eval (webpack-internal:///(api)/./src/pages/api/auth/login.ts:25:114) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { digest: undefined }
Within the NextJS documentation it states that we can have utils files, just use _utils for example.
Using this, I created my utils to make the most of my workflow and created a function called constructorApi.
Code below:
`import {withIronSessionApiRoute} from "iron-session/next";
import getConfig from "next/config";
import {NextApiHandler} from "next";
const { publicRuntimeConfig } = getConfig()
export default function constructorApi(closure: any): NextApiHandler {
return withIronSessionApiRoute(
closure,
{
cookieName: publicRuntimeConfig.IRON_SESSION_COOKIE_NAME,
password: publicRuntimeConfig.IRON_SESSION_COOKIE_PASSWORD,
// secure: true should be used in production (HTTPS) but can't be used in development (HTTP)
cookieOptions: {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
},
}
)
}`
The problem is not creating the file but using it.
I have another application without Sentry and I also tested it by deactivating Sentry from this same application and like magic everything works.
Below is the code for using constructorApi:
`import httpClient from "@/utils/httpClient";
import {createSession} from "@/pages/api/_utils/sessions/_createSession";
import constructorApi from "@/pages/api/_utils/_constructorApi";
export default constructorApi(
async function login(
req,
res
) {
if (req.method == 'POST') {
try {
});
`
When calling the /api/auth/login route in my case, the error highlighted at the beginning of this discussion occurs.
I would like to know if this is a bug in the sentry package or if it is a mistake I made.
If it is my error, I would like to understand a solution.
Beta Was this translation helpful? Give feedback.
All reactions