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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Use absolute path for distDir in webpack plugin options #6214

Merged

Conversation

lobsterkatie
Copy link
Member

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.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.51 KB (+0.06% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 60.36 KB (+0.05% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.17 KB (+0.08% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 53.71 KB (+0.03% 🔺)
@sentry/browser - Webpack (gzipped + minified) 19.9 KB (+0.04% 🔺)
@sentry/browser - Webpack (minified) 65.12 KB (+0.04% 🔺)
@sentry/react - Webpack (gzipped + minified) 19.93 KB (+0.07% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 45.89 KB (+0.03% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.33 KB (+0.04% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.74 KB (+0.06% 🔺)

@lobsterkatie lobsterkatie merged commit fae0682 into master Nov 16, 2022
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-use-abs-path-in-webpack-plugin-options branch November 16, 2022 21:20
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