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

Vercel + Nextjs cannot find Sentry CLI binary #8659

Closed
3 tasks done
Xhale1 opened this issue Jul 27, 2023 · 40 comments · Fixed by #9584
Closed
3 tasks done

Vercel + Nextjs cannot find Sentry CLI binary #8659

Xhale1 opened this issue Jul 27, 2023 · 40 comments · Fixed by #9584
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@Xhale1
Copy link

Xhale1 commented Jul 27, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.60.1

Framework Version

Next 13.4.12 and react 18.2.0

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. Setup a simple monorepo with Turborepo
  2. Copy over this nextjs app https://github.com/vercel/next.js/tree/canary/examples/with-sentry
  3. Upload to vercel

Expected Result

Source maps are uploaded properly.

Actual Result

The sentry upload reports the following error: error - Sentry CLI binary not found. Source maps will not be uploaded.

Screenshot 2023-07-26 at 8 21 41 PM
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Jul 27, 2023
@seongbin9786
Copy link

I'm sharing my observations! Hope it's relevant and could help somebody.

error screenshot

image

environment

  • yarn berry monorepo
  • next 13.3.4
  • sentry/nextjs latest(around 7.60.0)

cause

  • sentry/nextjs loads SentryWebpackPlugin (✅)
  • then it calls cliBinaryExists - which doen't exist (:x:)

temporary workaround

  • downgrade sentry/nextjs to 7.17.3
    • it's the latest version that doesn't call cliBinaryExists
    • cliBinaryExists appeared since 7.17.4(source code)

drawbacks of the workaround

  • Session Replay is not supported for the version (because the version is 9 months old).

possible fix

  • it might be okay to switch from SentryWebpackPlugin#cliBinaryExists to SentryWebpackPlugin#sentryCliBinaryExists.
  • I tried to change my locally-installed sentry's code and it solved the problem for latest sentry.
    • image

Give me a feedback if you need any further information or help. Thanks.

@AbhiPrasad
Copy link
Member

Related to #8541 - closing so we can have convos there.

@AbhiPrasad AbhiPrasad closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2023
@lforst
Copy link
Member

lforst commented Aug 1, 2023

Please check that your postinstall scripts are running when installing your dependencies

@Xhale1
Copy link
Author

Xhale1 commented Aug 4, 2023

I'm not entirely sure how to verify that. I'm using the default behavior for pnpm install which I believe includes postinstall scripts

I'm inclined to think they're working as I believe turborepo would have errors if they weren't.

@lforst
Copy link
Member

lforst commented Aug 7, 2023

@Xhale1 Please check if the sentry-cli binary is located in @sentry/cli/bin.

In any case. Vercel caches builds and dependecies. Can you try rerunning a build without cache? There's a checkbox in Vercel for that.

@hwkns
Copy link

hwkns commented Aug 15, 2023

Please check that your postinstall scripts are running when installing your dependencies

For any future googlers, this was our issue -- we had been using yarn install --immutable --mode=skip-build in CI, and the skip-build mode prevented post-install scripts from running, which prevented the sentry-cli binary from being found.

@thiemok
Copy link

thiemok commented Aug 19, 2023

I'm seeing the same issue with a project that was just recently switched to yarn.
The project is upgraded to @sentry/nextjs 7.64.0 and the sentry-cli binary seems to be available as far as I can tell.
Screenshot from 2023-08-19 11-57-12

next build prints the same three error messages as mentioned before.

@EvHaus
Copy link

EvHaus commented Aug 21, 2023

Just in case it helps others -- I was also having this issue and was able to resolve it by simply adding "@sentry/cli": "2.20.5" to my list of package.json dependencies. Before that I only had @sentry/nextjs.

@thiemok
Copy link

thiemok commented Aug 21, 2023

Explicitly adding @sentry/cli did not solve the problem for me. It's probably relevant to add that we're using multiple workspaces, pnp and zero-install and the issue happens on local builds as well

@lforst
Copy link
Member

lforst commented Aug 21, 2023

For anybody still experiencing this issue: Unfortunately it is impossible to troubleshoot this without reproduction so it would be really cool if you could provide a small repo or stackblitz or similar so we can actually resolve this.

@thiemok
Copy link

thiemok commented Aug 22, 2023

I've setup a minimal reproduction here: https://github.com/thiemok/sentry-yarn-resolution-test
You can see the error by running yarn workspace ui run build
Note: This is just the bare minimum the include the sentry webpack plugin, I've omitted any other sentry configs

@baptisteArno
Copy link

baptisteArno commented Aug 28, 2023

Same issue on a pnpm workspaces project with Turborepo. Deployment on Vercel.

Is there a manual command we can use to make sure the CLI is downloaded before the build script?

Note: it works if I redeploy without cache.

@leothorp
Copy link

leothorp commented Aug 29, 2023

@baptisteArno This workaround worked for us. Add a manual run of the cli install script as the first part of your buildCommand:

node /vercel/path0/node_modules/.pnpm/@sentry+cli@*/node_modules/@sentry/cli/scripts/install.js && \
...rest of your build command

@baptisteArno
Copy link

@baptisteArno This workaround worked for us. Add a manual run of the cli install script as the first part of your buildCommand:

node /vercel/path0/node_modules/.pnpm/@sentry+cli@*/node_modules/@sentry/cli/scripts/install.js && \
...rest of your build command

Awesome, that works 🙌

@thiemok
Copy link

thiemok commented Aug 30, 2023

Unfortunately that workaround seems to not work with yarn. I've added a pre build step to run
node ../../.yarn/unplugged/@sentry-cli-npm-1.75.2-bc4184e111/node_modules/@sentry/cli/scripts/install.js
That seems to execute the install script, which then happily prints
[sentry-cli] Using cached binary: /home/thiemok/.npm/sentry-cli/877528-sentry-cli-Linux- x86-64

This is then subsequently not found by the next build. I'm assuming thats because yarn pnp module resolution does not fall back to global npm packages.

Deleting the ~/.npm/sentry-cli folder and retrying then resulted in the install script downloading it into ~/.npm again

@lforst
Copy link
Member

lforst commented Aug 31, 2023

Thinking about adding a step to just download the binary during the build....

@codemilli
Copy link

Thinking about adding a step to just download the binary during the build....

Do you mean that if it doesn't find sentry-cli at build time, it downloads the sentry-cli binary from sentry's internal code?

@lforst
Copy link
Member

lforst commented Sep 7, 2023

Thinking about adding a step to just download the binary during the build....

Do you mean that if it doesn't find sentry-cli at build time, it downloads the sentry-cli binary from sentry's internal code?

Yep. So when you build your app, in the case you would upload source maps, the SDK just downloads the binary if it is not there and then continues the build.

@SYN0P
Copy link

SYN0P commented Sep 13, 2023

Yarn berry pnp solution

packageExtensions:
  '@sentry/utils@*':
    dependencies:
      '@sentry/webpack-plugin': '1.20.0'

Write this in yarnrc.yaml

@sentry/nextjs uses loadModule() to import @sentry/webpack-plugin.
but, loadMoudle() is in @sentry/utils and @sentry/utils has not @sentry/webpack-plugin dependency.
yarn berry pnp points out that this is ambiguous dependency.

(sorry bad english)

@saguilarolmo
Copy link

I have found the same problem that you are discussing in this thread. However, the solution you propose does not work for me.

In my case, I'm using Next 13.5.2, @sentry/nextjs 7.75.0 and @sentry/cli 2.21.2.

I have a monorepo with three Next projects, created with turborepo and deployed in Vercel. I have followed these Sentry docs to configure it in my Next projects https://docs.sentry.io/platforms/javascript/guides/nextjs/.

It seems that the errors are caught correctly in Sentry, but the sourcemaps are not loaded due to (I guess) the "error - Sentry CLI binary not found. Source maps will not be uploaded." message.

Regarding what you have talked about in the thread:

  • check if the sentry-cli binary is located in @sentry/cli/bin. -> Yes, the binary exists in my node-modules
  • Add a manual run of the cli install script as the first part of your buildCommand -> Running the command before my build command didn't work in my case.

Does anyone have more information on what the problem might be?

@lforst
Copy link
Member

lforst commented Oct 13, 2023

@saguilarolmo Can you try redeploying your project without build cache?

You can do this by redeploying and not clicking the checkbox in the screenshot.

Screenshot 2023-10-13 at 09 19 32

@saguilarolmo
Copy link

@iforst Yes, I tried that too. Sorry I forgot to mention it.
However, I've run it again just in case, but I get the same error :(

@lforst
Copy link
Member

lforst commented Oct 13, 2023

@iforst Yes, I tried that too. Sorry I forgot to mention it.
However, I've run it again just in case, but I get the same error :(

@saguilarolmo Hm that sucks. Just dumping a few things, please ignore if you already tried them:

  • Delete any .sentryclirc or sentry.properties files and redeploy without cache
  • Upgrade Next.js SDK to latest
  • Remove the direct dependency to @sentry/cli
  • Triple double check whether your package manager is running post-install scripts

@saguilarolmo
Copy link

Thank you very much @iforst!!
It seems that updating my Next.js SDK and removing @Sentry/cli solved my problem!

@rdsedmundo
Copy link

What's the final solution here? I think this should remain open, disabling the build cache entirely is not a feasible long-term solution.

@lforst
Copy link
Member

lforst commented Oct 18, 2023

@rdsedmundo You don't need to disable the build cache. Busting it once is enough.

@codemilli
Copy link

Yarn berry pnp solution

packageExtensions:
  '@sentry/utils@*':
    dependencies:
      '@sentry/webpack-plugin': '1.20.0'

Write this in yarnrc.yaml

@sentry/nextjs uses loadModule() to import @sentry/webpack-plugin. but, loadMoudle() is in @sentry/utils and @sentry/utils has not @sentry/webpack-plugin dependency. yarn berry pnp points out that this is ambiguous dependency.

(sorry bad english)

It works in my case, @lforst Should we add @sentry/webpack-plugin to the dependency list for @sentry/utils?

@lforst
Copy link
Member

lforst commented Oct 27, 2023

It works in my case, @lforst Should we add @sentry/webpack-plugin to the dependency list for @sentry/utils?

No this is not what we would want. @sentry/webpack-plugin is not a dependency of @sentry/utils.

@webjay
Copy link

webjay commented Oct 31, 2023

My build works with "next": "12.3.4", "@sentry/nextjs": "7.75.1"

But not with "next": "14.0.1", "@sentry/nextjs": "7.77.0":

import { withSentryConfig } from '@sentry/nextjs';

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  eslint: {
    dirs: ['.'],
  },
  sentry: {
    hideSourceMaps: true,
    autoInstrumentServerFunctions: true,
  },
  // experimental: { webpackBuildWorker: true },
};

const sentryWebpackPluginOptions = {
  silent: true,
};

export default withSentryConfig(nextConfig, sentryWebpackPluginOptions);

@lforst
Copy link
Member

lforst commented Oct 31, 2023

@webjay What is the exact error message?

@webjay
Copy link

webjay commented Oct 31, 2023

[13:23:09.396] ▲ Next.js 14.0.1
[13:23:09.396]
[13:23:09.396] Creating an optimized production build ...
[13:23:09.418] ⚠ Custom webpack configuration is detected. When using a custom webpack configuration, the Webpack build worker is disabled by default. To force enable it, set the "experimental.webpackBuildWorker" option to "true". Read more: https://nextjs.org/docs/messages/webpack-build-worker-opt-out
[13:23:09.802] error - Sentry CLI binary not found. Source maps will not be uploaded.
[13:23:09.802]
[13:23:09.804] error - Sentry CLI binary not found. Source maps will not be uploaded.
[13:23:09.804]
[13:23:09.806] error - Sentry CLI binary not found. Source maps will not be uploaded.

This was build without cache. I also tried experimental: { webpackBuildWorker: true }

@lforst
Copy link
Member

lforst commented Oct 31, 2023

@webjay Do you have something in your logs about node_modules being installed? I assume you're on Vercel.

@webjay
Copy link

webjay commented Oct 31, 2023

@lforst
Copy link
Member

lforst commented Nov 3, 2023

@webjay Since you're using bun you need to add @sentry/cli as a trusted dependency: https://bun.sh/guides/install/trusted

@neilpoulin
Copy link

neilpoulin commented Nov 7, 2023

I have a similar problem to @webjay but I dont have the webpack error message.

I'm switching an existing React project (custom webpack build) that used Sentry over to a next.js project (using default Next.js configs). I am an existing Sentry customer, and have done a number of integrations over the years, including with Nextjs.

I used the @sentry/wizard npx tool to set up my integration. I was able to see the example API error in the sentry UI.

When I start up my app, I get the "Can not find sentry CLI binary" message.

I will try downgrading Next.js since i'm currently running the latest 14.0.1 and perhaps that's causing issues.
Edit: I tried downgrading to the most recent Next 13 build, and the error was the same.
image

@bastiankistner
Copy link

Why is this issue closed? I just tried integrating sentry. I don't have the webpack installed anywhere as mentioned in the linked issue before this issue here was closed. I also tried the manual cli installation recommendation without luck. Quite sure it's due to nextjs 14. But some more info here would be great. I just wasted 2 hours of time setting up a logging tool. It would at least be great if @sentry could confirm this issue here still persists and there are no ETAs for a fix in sight. In that case I could consider a temporary switch to another tool. It's quite urgent to get proper stacktraces setup.

@lforst
Copy link
Member

lforst commented Nov 13, 2023

@bastiankistner Thank you for your concern. Trust me this is being looked at. I am also extremely annoyed by the persistence and frequency of this bug (because I have to keep explaining) and I keep bugging my manager to be able to allocate time to fix this.

@neilpoulin
Copy link

neilpoulin commented Nov 13, 2023

@bastiankistner I just got my setup working.

Short answer:
uninstalling @sentry/nextjs (npm uninstall @sentry/nextjs) and reinstalling (npm install @sentry/nextjs@latest) solved my problem.

Long answer:
I tried creating a minimal reproducible repo by creating a new nextjs project using create-next-app and then immediately installed @sentry/next via the wizard (npx @sentry/wizard@latest -i nextjs). It worked as expected, no build errors.

Running npm run dev resulted in no build errors. So then I started going through each config file one by one to spot any differences. All of my configs were virtually identical, and anything that wasn't, I changed in my real project to be identical. The bug still persisted.

I looked in node_modules/bin and confirmed that sentry-cli was present.

Next, I removed all caches/build folders: node_modules, .next, tsconfig.buildinfo. I then re-ran npm installand thennpm run dev`. The issue still persisted (can not find sentry-cli)

Feeling a bit stumped at this point with no obvious differences (same version of node, next, typescript, @sentry/next), I tried simply uninstalling @sentry/next (via npm uninstall @sentry/nextjs) and re-installing it (npm install @sentry/nextjs@latest).

My next build succeeded with no config changes!

So, perhaps there is some issue with existing projects when using the wizard to configure the sentry integration? I dont know. In any case, I hope this can help someone else.

@rdsedmundo
Copy link

Sharing how I have solved this in case it's helpful anyhow, given I had this problem and commented here a few weeks ago:

+  try {
+    const repoRoot = cp.execSync('git rev-parse --show-toplevel').toString('utf8').trim();
+
+    return path.join(
+      repoRoot,
+      'node_modules',
+      '.sentry-cli',
+      `${digest}-${path.basename(url).replace(/[^a-zA-Z0-9.]+/g, '-')}`
+    );    
+  } catch {}
+
   return path.join(
     npmCache(),
     'sentry-cli',

I simply changed where the binary is saved to be inside the node_modules folder instead of using the npmCache() function that Sentry implemented, which is a folder that Vercel doesn't save and there's no way to customize that.

@kristiegiles
Copy link

It works for me with @sentry/nextjs v7.33.0 and next v13.4.19, but I am unable to upgrade to next 14 without upgrading @sentry/nextjs. With the latest version of @sentry/nextjs, I get the sentry cli binary error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.