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

Module not found: Error: Can't resolve '@sentry/utils' #10266

Closed
3 tasks done
simPod opened this issue Jan 19, 2024 · 5 comments · Fixed by #10279
Closed
3 tasks done

Module not found: Error: Can't resolve '@sentry/utils' #10266

simPod opened this issue Jan 19, 2024 · 5 comments · Fixed by #10279

Comments

@simPod
Copy link

simPod commented Jan 19, 2024

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/browser

SDK Version

7.94.1

Framework Version

React 18.2.0

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. Use Yarn v4 with PnP
  2. Build with @sentry/browser and @sentry/react

Expected Result

No errors. v7.93.0 was fine.

Actual Result

Module not found: Error: Can't resolve '@sentry/utils' in '/yarn/global/cache/@sentry-internal-replay-canvas-npm-7.94.1-869cfbb282-10c0.zip/node_modules/@sentry-internal/replay-canvas/esm'

@lforst
Copy link
Member

lforst commented Jan 19, 2024

Yarn pnp is very broken. Please try clearing all of your package manager caches, delete node modules, and try reinstalling your dependencies. Thanks!

@jnoordsij
Copy link

jnoordsij commented Jan 19, 2024

Yarn pnp is very broken. Please try clearing all of your package manager caches, delete node modules, and try reinstalling your dependencies. Thanks!

I think Yarn PnP is right here: the newly introduced @sentry-internal/replay-canvas module does import/utilize the @sentry/utils module, but does not declare so in its dependencies. I think adding it there should resolve this issue.

@simPod
Copy link
Author

simPod commented Jan 19, 2024

Can you elaborate on why yarn pnp is very broken? I'd bet there are more issues with node modules than with pnp if we want to dive into such discussion. Btw there are no node modules with pnp but zipped packages. Therefore, the build is more reproducible with pnp.

Such errors occur when packages require other packages but does not declare them as dependencies. That works with node modules since there's no isolation and everything is mixed together nbut not pnp. Basically that's what @jnoordsij said.

I managed to fetch full error now

ERROR in ../../../../../.yarn/berry/cache/@sentry-internal-replay-canvas-npm-7.94.1-869cfbb282-10c0.zip/node_modules/@sentry-internal/replay-canvas/esm/index.js 1:0-47
Module not found: Error: Can't resolve '@sentry/utils' in '/Users/user/.yarn/berry/cache/@sentry-internal-replay-canvas-npm-7.94.1-869cfbb282-10c0.zip/node_modules/@sentry-internal/replay-canvas/esm'
resolve '@sentry/utils' in '/Users/user/.yarn/berry/cache/@sentry-internal-replay-canvas-npm-7.94.1-869cfbb282-10c0.zip/node_modules/@sentry-internal/replay-canvas/esm'
  Parsed request is a module
  using description file: /Users/user/.yarn/berry/cache/@sentry-internal-replay-canvas-npm-7.94.1-869cfbb282-10c0.zip/node_modules/@sentry-internal/replay-canvas/package.json (relative path: ./esm)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      request is not managed by the pnpapi
        @sentry-internal/replay-canvas tried to access @sentry/utils, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
        Required package: @sentry/utils
        Required by: @sentry-internal/replay-canvas@npm:7.94.1 (via /Users/user/.yarn/berry/cache/@sentry-internal-replay-canvas-npm-7.94.1-869cfbb282-10c0.zip/node_modules/@sentry-internal/replay-canvas/esm/)
 @ ../../../../../.yarn/berry/cache/@sentry-browser-npm-7.94.1-85b21ca3c0-10c0.zip/node_modules/@sentry/browser/esm/index.js 14:0-62 14:0-62
 @ ./src/index.ts 2:0-49 11:27-41

@Fonger
Copy link

Fonger commented Jan 22, 2024

The same error happens on pnpm

@lforst
Copy link
Member

lforst commented Jan 22, 2024

Can you elaborate on why yarn pnp is very broken?

@simPod I firmly believe yarn pnp (and I've also gotten reports where this applies to pnpm) is harmful to the ecosystem and a massive headache for maintainers for exactly the reason SvelteKit outlines:

The Plug'n'Play feature, aka 'pnp', is broken (it deviates from the Node module resolution algorithm, ...

node_modules may be big and inefficient but changing the semantics around it will inevitably break the ecosystem.

I do need to concede though that this issue may be a fuck-up on our part. As @jnoordsij has pointed out @sentry/utils is indeed imported by @sentry/replay-canvas. Thankfully, @Methuselah96 has opened a PR for this.

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

Successfully merging a pull request may close this issue.

4 participants