Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): CLI binary not found on Windows #6015

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/nextjs/rollup.npm.config.js
Expand Up @@ -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(
Expand Down
21 changes: 4 additions & 17 deletions 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';
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down