getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
8.01k stars 1.58k forks source link

Cannot destructure property 'sentryWebpackPlugin' of 'utils.loadModule(...)' as it is undefined #13665

Closed klaa97 closed 2 months ago

klaa97 commented 2 months ago

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

8.30.0

Framework Version

Next 13.4.7

Link to Sentry event

No response

Reproduction Example/SDK Setup

I have the following versions:

If I add the withSentryConfig to NextJS, such as this:

withSentryConfig(configWithPlugins, {
// private configs (org, project, token)
            hideSourceMaps: true,
            disableLogger: true,
        });

I get an error when building:

> Build error occurred
TypeError: Cannot destructure property 'sentryWebpackPlugin' of 'utils.loadModule(...)' as it is undefined.
    at Object.newWebpackFunction [as webpack] (/Users/project/node_modules/.pnpm/@sentry+nextjs@8.30.0_next@13.4.7+react@18.3.1/node_modules/@sentry/nextjs/build/cjs/config/webpack.js:324:15)
    at getBaseWebpackConfig (/Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/build/webpack-config.js:2113:32)
    at async Promise.all (index 1)
    at async Span.traceAsyncFn (/Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/trace/trace.js:103:20)
    at async webpackBuildImpl (/Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/build/webpack-build/impl.js:133:21)
    at async webpackBuild (/Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/build/webpack-build/index.js:137:16)
    at async /Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/build/index.js:558:123
    at async Span.traceAsyncFn (/Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/trace/trace.js:103:20)
    at async build (/Users/project/node_modules/.pnpm/next@13.4.7_37z3we5wden4rzgrojygioj2rq/node_modules/next/dist/build/index.js:145:29)

Steps to Reproduce

  1. Simple app with the versions I defined above
  2. If I add SentryWithConfig, it fails
  3. Otherwise, it does not

Expected Result

It succeeds the build

Actual Result

It fails the build with the error above

chargome commented 2 months ago

hey @klaa97, thanks for reaching out!

Are you using yarn with the pnp node-linker?

klaa97 commented 2 months ago

I am not configuring it explicitly, so I think I am using hoisted. (I am using pnpm)

chargome commented 2 months ago

Looks like it might still be related to https://github.com/getsentry/sentry-javascript/issues/13641

We'll have a look!

ibufu commented 2 months ago

It also failed with Next.js v14.2.8.

ibufu commented 2 months ago

@chargome Any workaround or suggestion?

chargome commented 2 months ago

@ibufu if you're using pnpm you can try setting node-linker to hoisted explicitly, I did not try this myself yet though

ibufu commented 2 months ago

@ibufu if you're using pnpm you can try setting node-linker to hoisted explicitly, I did not try this myself yet though

Thanks! I downgraded from 8.30.0 to 7.*. It works now.

ibufu commented 2 months ago

I spent a whole day figuring out why the sourcemap not uploaded on v7.x.

// @sentry/nextjs/cjs/config/webpack.js
const SentryWebpackPlugin = utils.loadModule('@sentry/webpack-plugin');

Finally I found SentryWebpackPlugin was undefined. Maybe utils.loadModule doesn't work with pnpm. So I added the following line into .npmrc then everything works well.

// .npmrc
hoist-pattern[]=*sentry*

I hope this can help people using pnpm monorepo. 🙏

chargome commented 2 months ago

@ibufu yes this was already clarified in https://github.com/getsentry/sentry-javascript/issues/13641 since we access node_modules there directly, sorry you burned so much time on this – but thanks for the pnpm workaround you provided!

chargome commented 2 months ago

closing this in favour of https://github.com/getsentry/sentry-javascript/issues/13641

duplicate of https://github.com/getsentry/sentry-javascript/issues/13641