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

@sentry/cli optional dependencies are not optional #1862

Closed
liamjones opened this issue Dec 7, 2023 · 15 comments
Closed

@sentry/cli optional dependencies are not optional #1862

liamjones opened this issue Dec 7, 2023 · 15 comments

Comments

@liamjones
Copy link

liamjones commented Dec 7, 2023

(If you are encountering this issue please 👍 this comment below)

Environment

@sentry/react-native 5.15.1 (w/ @sentry/cli 2.23.0)
Project with optional dependencies excluded from our project for other reasons not related to Sentry (via .yarnrc --install.ignore-optional true)

Steps to Reproduce

Tried to do a build after updating @sentry/react-native from 5.9.1 (w/ @sentry/cli 2.21.3)

Expected Result

iOS builds would work

Actual Result

iOS builds fail

Logs

Xcode build:

Node found at: /usr/local/bin/node
/Users/liam.jones/code/iris/node_modules/@sentry/cli/js/helper.js:116
      throw new Error(`Sentry CLI binary for this platform/architecture not found!
      ^

Error: Sentry CLI binary for this platform/architecture not found!

It seems like none of the "@sentry/cli" package's optional dependencies got installed. Please make sure your package manager is configured to install optional dependencies. If you are using npm to install your dependencies, please don't set the "--no-optional" or "--omit=optional" flags. Sentry CLI needs the "optionalDependencies" feature in order to install its binary.

If they're required dependencies why are they in optional dependencies in the package.json? Something to do with them being platform specific I guess?

@liamjones liamjones changed the title @sentry/cli optional dependencies are mandatory @sentry/cli optional dependencies are not optional Dec 7, 2023
@drazisil
Copy link

drazisil commented Dec 8, 2023

I think https://github.com/getsentry/sentry-react-native is the correct repro for this issue.

Although at a quick glance I believe you are correct in that these are the CLI binaries.

I'm not sure what would be a better option here. Maybe a postinstall: script that install one of these? I think people are even less likely to let those run. 🤔

Maybe use logic such as https://github.com/giggio/node-chromedriver, make it a required dependency, ant let it fetch the binary would be best.

This in my personal account, and any comments made under it are not related to any company or project I may work for

@liamjones
Copy link
Author

I'm not sure the Sentry RN repo is the right repo for this issue - if you had a plain node project that depended on @sentry/cli you'd hit the same issue - but it working something like the node-chromedriver example you posted looks like a good idea

@szokeasaurusrex
Copy link
Member

@liamjones, you are correct regarding the reason why these are marked as optional dependencies; it is because they are platform-specific. The dependency which contains the binary for your specific platform needs to be installed. Previously, we were using a post-install script to get the platform-specific binary, but we recently switched to using optional dependencies because the post-install script created issues for several people (see the issues linked on #1836 for context).

If you cannot enable optional dependencies, perhaps you might be able to manually add the correct dependency containing the sentry-cli binary for your platform?

@liamjones
Copy link
Author

liamjones commented Dec 12, 2023

If you cannot enable optional dependencies, perhaps you might be able to manually add the correct dependency containing the sentry-cli binary for your platform?

I'm not sure we can do that, we have devs on multiple different platform architectures. Looks like I should be able to defer to the CLI installed on the host machine (e.g. via homebrew) which would already be platform appropriate?

if (process.env.SENTRY_BINARY_PATH) {

@lforst
Copy link
Member

lforst commented Dec 13, 2023

So in general, the thing I recommend doing is enabling optional dependencies. If that doesn't work for you, you can pin Sentry CLI to a version before 2.22.3.

You could also run the install script that is contained in the package and provide a SENTRY_BINARY_PATH environment variable pointing to the downloaded binary.

@drazisil is right. People are even less likely to enable postinstall scripts which is the alternative here. Long term we can think about adding back a postinstall script that will install the binary if we can't find optional dependencies but we will make the timeline around that dependent on how many people run into this.

@liamjones
Copy link
Author

Thanks all, I've been able to able to change some things in our setup so we can re-enable optional dependencies for now.

Long term we can think about adding back a postinstall script that will install the binary if we can't find optional dependencies but we will make the timeline around that dependent on how many people run into this.

@lforst regarding this point - do you want me to keep this issue open for other people who might run into it or close it since I've worked around the issue for our setup?

@lforst
Copy link
Member

lforst commented Dec 13, 2023

@liamjones Feel free to keep it open. I think you're raising a good point that we need to provide an escape hatch for people who don't have support for optional dependencies.

@liamjones
Copy link
Author

Another potential suggestion? If the dependency is missing and SENTRY_BINARY_PATH isn't specified the helper could potentially fallback to looking for sentry-cli on the system PATH before giving up?

@lforst
Copy link
Member

lforst commented Dec 13, 2023

@liamjones Maybe yes, the issue I have with that is that it goes completely around the Node.js resolution algorithm and that this behavior would be very random. People could have different versions of the CLI installed globally (via brew for example) and it would be picked up by this mechanism.

@szokeasaurusrex
Copy link
Member

szokeasaurusrex commented Dec 13, 2023

I agree with @lforst, let's keep this issue open in case others run into the same problem.

If you encounter this same issue, please add a 👍 to this comment to help us gauge interest in creating an alternative installation mechanism for folks who cannot use optional dependencies.

@n10v
Copy link

n10v commented Dec 13, 2023

We had similar issue, but with different reason.

We just integrated Sentry into our web app. I installed it via npm install @sentry/vite-plugin --save-dev on my Mac. It was working correctly locally on my Mac, but after I deployed to our Github repo and executed CI job, it failed with same error as from @liamjones.

We figured out that when I installed Sentry on my Mac, only node_modules/@sentry/cli-darwin was added to package-lock.json. However, we use Linux on our CI. After I added following lines to our package.json and executed npm install, the CI jobs started to work:

      "optionalDependencies": {
        "@sentry/cli-darwin": "2.22.3",
        "@sentry/cli-linux-x64": "2.22.3"
      }

See relevant issue on npm: npm/cli#4828

@electrovir
Copy link

Just ran into this while trying to use @sentry/webpack-plugin. I think it's silly that "optional" dependencies are required here, but I also see (thanks @n10v) that there's an npm bug around this. However, I'd also point out that esbuild also uses optional dependencies and I've never had issues with them.

@isimmons
Copy link

isimmons commented Jan 3, 2024

I just had the same issue deploying to an Astro project with Sentry integration to Vercel. I develop on a Windows PC so the only binary installed was the windows binary but for whatever reason it doesn't work on Vercel.

Not knowing which platform Vercel needs, I copied the whole block of optionalDependencies from @sentry/cli/package.json into my projects package.json, deleted node_modules and the lock file. Now I get the correct binary on dev and production.

@liamjones
Copy link
Author

Not knowing which platform Vercel needs, I copied the whole block of optionalDependencies from @sentry/cli/package.json into my projects package.json, deleted node_modules and the lock file. Now I get the correct binary on dev and production.

Which is fine for now but keep in mind that if you update the Sentry dependency and they change these optional dependency versions you'll also need to make sure you update your copied block to keep it in sync.

@lforst
Copy link
Member

lforst commented Jan 4, 2024

This issue should be solved with #1874. Please upgrade the @sentry/cli package and check if the problem is fixed.

For reference, we have another thread with some more information: #1849

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

No branches or pull requests

7 participants