Skip to content

Instrumentation.ts runs server-side and client-side #56968

Answered by crummy
crummy asked this question in Help
Discussion options

You must be logged in to vote

I have resolved my issue (thanks to StackOverflow) but got very confused along the way. This code works fine:

export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await import("os")
  }
}

However, this code does not.

export async function register() {
  const isServer = process.env.NEXT_RUNTIME === "nodejs"
  if (isServer) {
    await import("os")
  }
}

Why????

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@crummy
Comment options

Answer selected by crummy
Comment options

You must be logged in to vote
5 replies
@crummy
Comment options

@karlhorky
Comment options

@anaisbetts
Comment options

@crummy
Comment options

@teddis
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
5 participants