Skip to content

Module not found: Can't resolve '@sentry/utils/esm/buildPolyfills' #8180

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

Closed
HoJin9622 opened this issue May 20, 2023 · 30 comments · Fixed by #9467
Closed

Module not found: Can't resolve '@sentry/utils/esm/buildPolyfills' #8180

HoJin9622 opened this issue May 20, 2023 · 30 comments · Fixed by #9467
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@HoJin9622
Copy link

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

"next": "^13.4.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"

use app dir

  1. npx @sentry/wizard@latest -i nextjs
  2. npm run dev
  3. Error Occrued!

Expected Result

It works without any problems.

Actual Result

./app/posts/[slug]/page.tsx
Module not found: Can't resolve '@sentry/utils/esm/buildPolyfills'

https://nextjs.org/docs/messages/module-not-found

Product Area

Unknown

Link

No response

DSN

No response

Version

7.52.1

@getsantry
Copy link

getsantry bot commented May 20, 2023

Assigning to @getsentry/support for routing, due by Monday, May 22nd at 5:00 pm (sfo). ⏲️

@JLuse JLuse transferred this issue from getsentry/sentry May 22, 2023
@lforst
Copy link
Contributor

lforst commented May 22, 2023

Hey, can you share a small reproduction app where this is happening thank you!

@lforst lforst added Status: Needs Reproduction Package: nextjs Issues related to the Sentry Nextjs SDK and removed Status: Unrouted labels May 22, 2023
@tubbo
Copy link

tubbo commented May 23, 2023

This also happened to me in an application using Yarn Berry (v3.5.1) and PnP on NextJS. @sentry/nextjs kept erroring in the build with this exact same error, until I set nodeLinker: node-modules in my .yarnrc.

Screenshot 2023-05-23 at 2 32 31 PM

I also tried unplugging @sentry/nextjs as well as next itself, but that didn't seem to do anything. I suspect some dependency of the next build process is the culprit here...

@Huespal
Copy link

Huespal commented May 30, 2023

Hello.
Our team is experiencing the same.
Do you have a date when it will be fixed?
Thank you.

@lforst
Copy link
Contributor

lforst commented May 30, 2023

@Huespal so far nobody provided a reproduction example, which we would need in order to fix this bug.

@HoJin9622
Copy link
Author

Reproduction app
This error occurs in a project using yarn berry.

@lforst
Copy link
Contributor

lforst commented Jun 6, 2023

Ok since this is working for all other package managers do you mind opening an upstream issue in yarn berry for this? Thanks.

@HoJin9622
Copy link
Author

Ok since this is working for all other package managers do you mind opening an upstream issue in yarn berry for this? Thanks.

Okay. I'll create an upstream issue.

@twavv
Copy link
Contributor

twavv commented Aug 3, 2023

@mydea @lforst This is not a bug in Yarn. Yarn requires packages to strictly declare their dependencies and will raise an error if a package attempts to import something it hasn't declared.

I believe(*) in this case the reason it fails is because the Sentry NextJS plugin adds some extra code in the various files in app/ to do its early initialization magic, but that adds imports to @sentry/utils for polyfills. If a user has only @sentry/nextjs explicitly installed, Yarn will have a fit if @sentry/utils is imported from within the project since the project doesn't explicitly declare @sentry/utils as a dependency. ((It's fine to import @sentry/utils from inside the @sentry/nextjs package, but from Yarn's perspective, we're trying to import @sentry/utils from the app itself, not the @sentry/nextjs package))

The quickest fix for this is just to explicitly add @sentry/utils as a dependency to your project. Beyond that, can @sentry/nextjs be made to avoid importing @sentry/utils in this way?

(* I'm making some educated guesses here, but I'm not familiar with how the Sentry integration actually hooks into NextJS so it might be off base)

@lforst lforst reopened this Sep 14, 2023
@lforst
Copy link
Contributor

lforst commented Sep 14, 2023

is it worth providing a reproduction?

@sebpowell Yes please. We have yet to receive proper repro on this.

@mayank1513
Copy link

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Sep 14, 2023
@lforst
Copy link
Contributor

lforst commented Sep 14, 2023

@mayank1513 Thanks can you provide instructions on how to reproduce. Thanks!

@mayank1513
Copy link

clone the branch or create codespace then

pnpm i && pnpm build && pnpm next-with-deps ./examples/with-sentry

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Sep 14, 2023
@lforst
Copy link
Contributor

lforst commented Sep 14, 2023

@mayank1513 your repro is failing due to issues unrelated to sentry:

@next/react-dev-overlay:build: src/internal/helpers/launchEditor.ts(217,5): error TS2322: Type 'ParseEntry[]' is not assignable to type 'string[]'.
@next/react-dev-overlay:build:   Type 'ParseEntry' is not assignable to type 'string'.
@next/react-dev-overlay:build:     Type '{ op: ControlOperator; }' is not assignable to type 'string'.
@next/react-dev-overlay:build:  ELIFECYCLE  Command failed with exit code 2.
@next/react-dev-overlay:build: ERROR: command finished with error: command (/workspaces/clones/next.js/packages/react-dev-overlay) pnpm run build exited (1)

@yashsway
Copy link

yashsway commented Oct 24, 2023

Attempting to add Sentry to my Next.js project (using App Router and pnpm) using the Sentry Wizard:

npx @sentry/wizard@latest -i nextjs

I get this error:
image

Update:
For anyone coming here using pnpm and NextJS App Router - install @sentry/utils manually after everything the Sentry Wizard installs and sets up for your project. This fixes it! ✅ Not sure why this isn't installed by the wizard.

pnpm install @sentry/utils

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 24, 2023
@geoffdavis92
Copy link

I was running into this similar problem, and it turns out in my Webpack configuration (technically the config function that I send through my 11ty Webpack plugin config) I had at one time added ".js" to the resolve.extensions array, and subsequently removed it.

I determined that removing that entry in part caused this issue to occur.

Adding the .js extension back solved the issue.

Here's an abridged section of my plugin's Webpack config object:

// ...
module: {
  rules: [
    // I'm extending a default configuration
    ...defaultWebpackConfig.module.rules,
    {
      test: /\.ts$/,
      use: "ts-loader",
      exclude: /node_modules|\.d\.ts$/,
    },
  ],
},
resolve: {
  extensions: [".ts", ".js"],
}
// ...

For reference, here's my tsconfig:

{
  "include": ["./src/js/**/*"],
  "exclude": ["node_modules"],
  "compilerOptions": {
    "target": "ES2015",
    "moduleResolution": "node",
    "allowJs": true,
    "module": "ES6",
    "lib": ["es2022", "dom", "dom.iterable"],
    "sourceMap": true,
    "inlineSources": true,

    // Set `sourceRoot` to  "/" to strip the build path prefix
    // from generated source code references.
    // This improves issue grouping in Sentry.
    "sourceRoot": "/"
  }
}

@kirbysayshi
Copy link

I'm fairly certain that if you are using pnpm or yarn berry, you'll still need to manually add @sentry/utils as a directly dependency to your nextjs project. Otherwise you'll get a variant of the original error reported!

image
pnpm add @sentry/utils

@lforst
Copy link
Contributor

lforst commented Feb 9, 2024

As a positive outlook: We aim to fix this reliably with the new major of the SDK! Sorry for the trouble this has caused. We have a bit of tech debt here.

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
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

13 participants