Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs): Add distDirOverride #6194

Closed
wants to merge 1 commit into from

Conversation

tmilewski
Copy link

Problem

We're using a monorepo (Nx) and it runs the NextJS build process in ./apps/web with the distDir set to ../../dist/apps/web/.next.

The CLI is being run at the root of the monorepo. As such, ../../dist/apps/web/.next doesn't find anything when it goes to upload the source maps.

Proposed Solution

This allows a developer to set the distDir for the CLI without compromising the Next distDir.

Order of importance:

  1. distDirOverride in the Next sentry config object.
  2. distDir in the Next config.
  3. .next

Didn't really know what to name it so, in the interim, stuck with distDirOverride. 馃し

image

@lobsterkatie
Copy link
Member

Hi, again, @tmilewski! Thanks for this. You raise an interesting scenario we hadn't thought of. Rather than making the user override the distDir value, though, I think this is something we should handle automatically, which we can do by passing an absolute, rather than a relative, path to @sentry/cli. I've implemented that in #6214.

Thanks for pointing out this use case!

lobsterkatie added a commit that referenced this pull request Nov 16, 2022
#6214)

In nextjs, the output directory (`distDir`) is specified by the user and stored in memory as a relative path. It's then used in two places:

- At build time, it's resolved against the project directory, in order to know where to output built files.
- At runtime, it's resolved against the working directory, in order to know where to find those built files.

In the nextjs SDK, we also use the value in two places:

- At build time, we pass it to `@sentry/cli` via Sentry webpack plugin options. `sentry/cli` then resolves it against its working directory, so that it knows where to find built files to upload.
- At runtime, we grab it from `global.__rewriteFramesDistDir__` (where we've stashed it at build time via our prefix loader), and then resolve it against the working directory, so the `RewriteFrames` integration knows what value to strip from stackframe paths.

At runtime, this resolution always works, because it matches what nextjs itself does. At build time, it also works... most of the time.  But in the case where the project directory and `@sentry/cli`'s working directory don't match, it leads to `@sentry/cli` not being able to find the files it needs to upload. (This can happen if, for example, the app is a package in a monorepo - located at `packages/nextjsApp`, say - and `@sentry/cli` is running from the monorepo's root level `node_modules`.)

This fixes that by resolving the `distDir` value against the project directory (thereby turning it into an absolute path) before passing it to `@sentry/cli`. That way, no resolution on `@sentry/cli`'s part is necessary, preventing the mismatch.

Fixes the problem outlined in #6194.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants