diff --git a/packages/nextjs/rollup.npm.config.js b/packages/nextjs/rollup.npm.config.js index 04d4675eda63..03e1f5d8d40a 100644 --- a/packages/nextjs/rollup.npm.config.js +++ b/packages/nextjs/rollup.npm.config.js @@ -7,9 +7,15 @@ export default [ // doesn't automatically include it when calculating the module dependency tree. entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/utils/instrumentServer.ts'], - // prevent this internal nextjs code from ending up in our built package (this doesn't happen automatially because - // the name doesn't match an SDK dependency) - packageSpecificConfig: { external: ['next/router'] }, + packageSpecificConfig: { + external: [ + // prevent this internal nextjs code from ending up in our built package (this doesn't happen automatically because + // the name doesn't match an SDK dependency) + 'next/router', + // We need to exclude the cli since we use it to get the binary path and it's not a direct dependency + '@sentry/cli', + ], + }, }), ), ...makeNPMConfigVariants( diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 9cdfe2753e51..aa32f5d999f2 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -1,4 +1,6 @@ /* eslint-disable max-lines */ +// eslint-disable-next-line import/no-extraneous-dependencies +import * as SentryCLI from '@sentry/cli'; import { getSentryRelease } from '@sentry/node'; import { arrayify, dropUndefinedKeys, escapeStringForRegex, logger } from '@sentry/utils'; import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin'; @@ -456,22 +458,6 @@ export function getWebpackPluginOptions( return { ...defaultPluginOptions, ...userPluginOptions }; } -/** - * NOTE: We're faking `require.resolve` here as a workaround for @vercel/nft detecting the binary itself as a hard - * dependency and always including it in the bundle, which is not what we want. - * - * ref: https://github.com/getsentry/sentry-javascript/issues/3865 - * ref: https://github.com/vercel/nft/issues/203 - */ -function ensureCLIBinaryExists(): boolean { - for (const node_modulesPath of module.paths) { - if (fs.existsSync(path.resolve(node_modulesPath, '@sentry/cli/sentry-cli'))) { - return true; - } - } - return false; -} - /** Check various conditions to decide if we should run the plugin */ function shouldEnableWebpackPlugin(buildContext: BuildContext, userSentryOptions: UserSentryOptions): boolean { const { isServer, dev: isDev } = buildContext; @@ -485,7 +471,8 @@ function shouldEnableWebpackPlugin(buildContext: BuildContext, userSentryOptions // architecture-specific version of the `sentry-cli` binary. If `yarn install`, `npm install`, or `npm ci` are run // with the `--ignore-scripts` option, this will be blocked and the missing binary will cause an error when users // try to build their apps.) - if (!ensureCLIBinaryExists()) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any + if (!fs.existsSync((SentryCLI as any).getPath())) { return false; }