Skip to content

Use utils in the NextJs API #9133

@lucasantoniooficial

Description

@lucasantoniooficial

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.64.0

Framework Version

NextJs 13.3.1

Link to Sentry event

No response

SDK Setup

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: "",
release: front-end@${process.env.APP_VERSION},
integrations: [
new Sentry.BrowserTracing(),
new Sentry.Replay(),
],
tracesSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
autoSessionTracking: true
});

Steps to Reproduce

    1. First install the iron-session package: https://github.com/vvo/iron-session
  1. First create the _utils folder inside page/api
  2. Create the file _constructorApi.ts file model is in the link: Problem with utils within the API #9132
  3. Import the constructorApi into some api file, for example login, there is a ready example also in the link: Problem with utils within the API #9132

Expected Result

API needs to work normally as it should, in case the login logs in and creates the session.

Actual Result

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 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions