Skip to content

Commit

Permalink
feat(nextjs): Warn about Turbopack incompatibility (#657)
Browse files Browse the repository at this point in the history
* feat(nextjs): Warn about Turbopack incompatibility

* changelog
  • Loading branch information
lforst authored Sep 4, 2024
1 parent 3a57116 commit 3c92e8a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- feat(nextjs): Warn about Turbopack incompatibility (#657)
- feat(sveltekit): Add feature selection (#648)

## 3.27.0
Expand Down
47 changes: 44 additions & 3 deletions src/nextjs/nextjs-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,25 @@ export async function runNextjsWizardWithTelemetry(

await addDotEnvSentryBuildPluginFile(authToken);

const isLikelyUsingTurbopack = await checkIfLikelyIsUsingTurbopack();
if (isLikelyUsingTurbopack || isLikelyUsingTurbopack === null) {
await abortIfCancelled(
clack.select({
message: `Warning: The Sentry SDK doesn't yet fully support Turbopack in dev mode. The SDK will not be loaded in the browser, and serverside instrumentation will be inaccurate or incomplete. Production builds will still fully work. ${chalk.bold(
`To continue this setup, if you are using Turbopack, temporarily remove \`--turbo\` from your dev command until you have verified the SDK is working as expected.`,
)}`,
options: [
{
label: 'I understand.',
hint: 'press enter',
value: true,
},
],
initialValue: true,
}),
);
}

const mightBeUsingVercel = fs.existsSync(
path.join(process.cwd(), 'vercel.json'),
);
Expand All @@ -309,13 +328,18 @@ export async function runNextjsWizardWithTelemetry(
await traceStep('configure-ci', () => configureCI('nextjs', authToken));
}

clack.outro(`
${chalk.green('Successfully installed the Sentry Next.js SDK!')} ${
clack.outro(`${chalk.green(
'Successfully installed the Sentry Next.js SDK!',
)}${
shouldCreateExamplePage
? `\n\nYou can validate your setup by restarting your dev environment (${chalk.cyan(
? `\n\nYou can validate your setup by (re)starting your dev environment (${chalk.cyan(
`next dev`,
)}) and visiting ${chalk.cyan('"/sentry-example-page"')}`
: ''
}${
shouldCreateExamplePage && isLikelyUsingTurbopack
? `\nDon't forget to remove \`--turbo\` from your dev command until you have verified the SDK is working. You can safely add it back afterwards.`
: ''
}
${chalk.dim(
Expand Down Expand Up @@ -925,3 +949,20 @@ async function askShouldEnableReactComponentAnnotation() {
return shouldEnableReactComponentAnnotation;
});
}

/**
* Returns true or false depending on whether we think the user is using Turbopack. May return null in case we aren't sure.
*/
async function checkIfLikelyIsUsingTurbopack(): Promise<boolean | null> {
let packageJsonContent: string;
try {
packageJsonContent = await fs.promises.readFile(
path.join(process.cwd(), 'package.json'),
'utf8',
);
} catch {
return null;
}

return packageJsonContent.includes('--turbo');
}

0 comments on commit 3c92e8a

Please sign in to comment.