Skip to content

NextJS: Edge runtime imports index.client.js in development #8274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
isaacseymour opened this issue Jun 1, 2023 · 3 comments
Closed
3 tasks done

NextJS: Edge runtime imports index.client.js in development #8274

isaacseymour opened this issue Jun 1, 2023 · 3 comments
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@isaacseymour
Copy link

isaacseymour commented Jun 1, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

7.53.1

Framework Version

NextJS 13.4.3

Link to Sentry event

No response

SDK Setup

sentry.edge.config.js:

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

const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;

Sentry.init({
  dsn: SENTRY_DSN,
  environment: process.env.APP_ENV || "development",
  release: process.env.VERCEL_GIT_COMMIT_SHA,
  tracesSampleRate: 0.0,
  initialScope: {
    tags: {
      vercel_env: process.env.NEXT_PUBLIC_VERCEL_ENV,
      deployment_url: `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`,
    },
  }
});

Steps to Reproduce

Create a NextJS app. In next.config.js, set sentry.excludeServerRoutes to /.*/ and manually wrap the server component (to work around #8062).

Make a page that's rendered on the edge runtime, manually wrapped (also working around #8062!). E.g.:

// page.jsx
import { wrapServerComponentWithSentry } from "@sentry/nextjs";

export const runtime = "edge";

async function Page() {
  return <div>Hello!</div>;
}

export default wrapServerComponentWithSentry(Page, {
  componentRoute: "/",
  componentType: "Page",
});

Run next dev.

Expected Result

Page should render "Hello!"

Actual Result

image
@isaacseymour
Copy link
Author

Workaround

Adding this to next.config.js seems to sort things out:

webpack: (config, options) => {
  if (options.isServer && options.nextRuntime === "edge") {
    config.resolve.alias["@sentry/nextjs"] = path.resolve("./node_modules/@sentry/nextjs/esm/edge")
  }

  return config;
},

Suggested solution

I think the issue here is that the package.json for @sentry/nextjs has module and browser keys, but no worker key. Based on this discussion, it seems like the recommendation is for libraries to have "worker": "... edge version here ..."

So for Sentry that would be "worker": "esm/edge/index.js".

@lforst lforst self-assigned this Jun 5, 2023
@lforst lforst added the Package: nextjs Issues related to the Sentry Nextjs SDK label Jun 5, 2023
@lforst
Copy link
Contributor

lforst commented Jun 5, 2023

@isaacseymour I sadly cannot reproduce the error with the steps you provide. Can you please share the full error, your next.config.js, and a minimal reproduction example? Thanks!

@isaacseymour
Copy link
Author

Hmm, I also can't repro it in a fresh repo. There must be some interaction with another bit of config somewhere, but I can't think what :(

@isaacseymour isaacseymour closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
None yet
Development

No branches or pull requests

2 participants