Skip to content

Empty api responses on OpenNext/SST #9035

@MaxiMittel

Description

@MaxiMittel

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.69.0

Framework Version

NextJS 12.3.0

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

We are moving our existing NestJS from Amplify Hosting to AWS Lambda. We chose to use the cdk and the cdk-nextjs npm package. (GitHub: cdk-nextjs). This is built upon the OpenNext package from SST.

We were able to deploy the app using the stated packages without any trouble, but all of our API routes returned nothing. After some investigation we concluded that it's related to sentry, when we removed the withSentryConfig from our next.config.js the api routes started working again. What's weird is that the same code with sentry works on Amplify but does not with OpenNext.

Expected Result

Api routes should return something.

Actual Result

This is my next.config.js:

const { withSentryConfig } = require("@sentry/nextjs");

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fallback = {
        fs: false,
      };
    }
    return config;
  },
  env: {...},
  sentry: {
    hideSourceMaps: true,
    excludeServerRoutes: ["/api/auth/[...nextauth]"],
  },
  images: {...},
};

const sentryWebpackPluginOptions = {
  silent: true,
};

//console.dir(process.env, { depth: null });

module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);

Even the most basic endpoints fail, the status code gets set correctly but no information is sent.

import type { NextApiRequest, NextApiResponse } from "next";

async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
  res.status(201).json({ message: "success" });
}

export default handler;

There is no error anywhere, not in Sentry not in CloudWatch it's just an empty response. Did anybody encounter something similar and has a solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions