Skip to content

Commit 85c754a

Browse files
authored
docs: Clarify Node.js specific imports in Next.js register hook migration guide (#11878)
1 parent 3355a05 commit 85c754a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

MIGRATION.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,24 @@ The following is an example of how to initialize the serverside SDK in a Next.js
833833
}
834834
```
835835

836+
If you need to import a Node.js specific integration (like for example `@sentry/profiling-node`), you will have to
837+
import the package using a dynamic import to prevent Next.js from bundling Node.js APIs into bundles for other
838+
runtime environments (like the Browser or the Edge runtime). You can do so as follows:
839+
840+
```ts
841+
import * as Sentry from '@sentry/nextjs';
842+
843+
export async function register() {
844+
if (process.env.NEXT_RUNTIME === 'nodejs') {
845+
const { nodeProfilingIntegration } = await import('@sentry/profiling-node');
846+
Sentry.init({
847+
dsn: 'YOUR_DSN',
848+
integrations: [nodeProfilingIntegration()],
849+
});
850+
}
851+
}
852+
```
853+
836854
Note that you can initialize the SDK differently depending on which server runtime is being used.
837855

838856
If you are using a

0 commit comments

Comments
 (0)