Skip to content

fix(nextjs): Use correct abs path for server init #3649

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

Merged
merged 5 commits into from
Jun 4, 2021

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jun 4, 2021

This fixes a bug caused by next build being run on a different machine than next start. Because we've been setting the env var SENTRY_SERVER_INIT_PATH (which we do during build) as an absolute, rather than relative, path, changing machines has made that path invalid when it's later used during server startup. This switches to using a relative path, so that it will work regardless of the machine on which it's run.

Separately, it also fixes a bug where the path (absolute or relative) to the server init file was incorrect when using webpack 5. Under webpack 5, the path in the webpack config's output.path variable points to a different location (one directory deeper) than in webpack 4. To compensate for that difference, the config (as created by next) has a different output.filename value (one including ../ at the beginning), so that then combination points to the same spot as under webpack 4. This PR takes advantage of that by including filename in it derivation of the server init file's final location.

Closes #3648

@AbhiPrasad AbhiPrasad requested a review from lobsterkatie June 4, 2021 15:24
@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.83 KB (-0.01% 🔽)
@sentry/browser - Webpack 22.07 KB (0%)
@sentry/react - Webpack 22.11 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.23 KB (-0.01% 🔽)

@AbhiPrasad AbhiPrasad force-pushed the abhi/nextjs-relative-server-init branch from 1549fda to 0d1c36f Compare June 4, 2021 19:02
@AbhiPrasad AbhiPrasad marked this pull request as ready for review June 4, 2021 19:02
@AbhiPrasad AbhiPrasad requested a review from kamilogorek as a code owner June 4, 2021 19:02
Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) June 4, 2021 19:49
@AbhiPrasad AbhiPrasad merged commit e46451e into master Jun 4, 2021
@AbhiPrasad AbhiPrasad deleted the abhi/nextjs-relative-server-init branch June 4, 2021 20:02
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.

Nextjs "server Sentry.Init()" is never called if npm run build happened in different environment than hosting
2 participants