Skip to content

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

Description

@jtn-junedesk

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node(raven for node)
  • other: @sentry/nextjs

Version:

6.5.1

Description

I use Github Actions to build my nextjs application, then deploy artifacts to a NodeJS Server hosted elsewhere.
https://nextjs.org/docs/deployment#nodejs-server

During npm run build @sentry/nextjs creates a file .env.local and sets an environment variable SENTRY_SERVER_INIT_PATH. The value of said variable is an absolute path i.e. C:\some_path_to_project\.next\server\sentry\initServerSDK.js

During npm run start process.env.SENTRY_SERVER_INIT_PATH is used to require initServerSDK.js. However, npm run start is called after artifacts have been uploaded to a different environment running a NodeJS server. Because of this, the absolute path of process.env.SENTRY_SERVER_INIT_PATH is no longer valid.

initServerSDK.js cannot be found and Sentry.Init() is never called - serverside logging does not happen.

Source code

setRuntimeEnvVars(projectDir,{SENTRY_SERVER_INIT_PATH: serverSDKInitOutputPath});

require(process.env.SENTRY_SERVER_INIT_PATHasstring);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions