Skip to content

autoInstrumentServerFunctions breaks when the API route has a CJS export #5863

Closed
@cahaseler

Description

@cahaseler

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

"@sentry/nextjs": "7.14.0"

Framework Version

"next": "12.3.1"

Link to Sentry event

https://sentry.io/organizations/doe-pars/issues/3634865618/?query=is%3Aunresolved

Steps to Reproduce

Enable the new autoInstrumentServerFunctions. Create a NextJS API route and set module.exports= apiName rather than using export default. I haven't tested it with an anonymous function.

Expected Result

The API route works and is instrumented by Sentry. Or at least I get a better error than the route mysteriously not working and no log messages.

Actual Result

TypeError
Cannot read properties of undefined (reading 'name')

From within Sentry's code:
/usr/src/app/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryAPI.js

image

Workaround for others who Google this:

Do an export default and name the function and it will work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions