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

"Build failed because of webpack errors" when using client code in NextJS React-App #14237

Closed
3 tasks done
DavidHaintz opened this issue Nov 11, 2024 · 1 comment
Closed
3 tasks done
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@DavidHaintz
Copy link

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.37.1

Framework Version

Next.js 15.0.1

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

Create a new React-App with NextJS:
npx create-next-app@latest

√ Would you like to use TypeScript? ... Yes
√ Would you like to use ESLint? ... Yes
√ Would you like to use Tailwind CSS? ... Yes
√ Would you like your code inside a `src/` directory? ... Yes
√ Would you like to use App Router? (recommended) ... Yes
√ Would you like to use Turbopack for next dev? ... No
√ Would you like to customize the import alias (@/* by default)? ... No

Add following code on the top of layout.tsx and page.tsx:

'use client'

This is the step that causes the error, but I need everything to be client only.

Now you can set up sentry as described in the documentation. I tried the wizard, as well as this: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

npx @sentry/wizard@latest -i nextjs
(I said no to proxiing the requests).

Expected Result

No error when building.

Actual Result

It uploads the sourcemaps, but exits with following error log:

   Creating an optimized production build ...
Failed to compile.

./node_modules/@opentelemetry/instrumentation-amqplib/build/src/index.js
Self-reference dependency has unused export name: This should not happen

Import trace for requested module:
./node_modules/@opentelemetry/instrumentation-amqplib/build/src/index.js
./node_modules/@sentry/node/build/cjs/integrations/tracing/amqplib.js
./node_modules/@sentry/node/build/cjs/index.js
./node_modules/@sentry/nextjs/build/cjs/index.server.js
./src/app/page.tsx

./node_modules/@opentelemetry/instrumentation-amqplib/build/src/types.js
Self-reference dependency has unused export name: This should not happen

Import trace for requested module:
./node_modules/@opentelemetry/instrumentation-amqplib/build/src/types.js
./node_modules/@opentelemetry/instrumentation-amqplib/build/src/index.js
./node_modules/@sentry/node/build/cjs/integrations/tracing/amqplib.js
./node_modules/@sentry/node/build/cjs/index.js
./node_modules/@sentry/nextjs/build/cjs/index.server.js
./src/app/page.tsx

./node_modules/@opentelemetry/instrumentation-connect/build/src/enums/AttributeNames.js
Self-reference dependency has unused export name: This should not happen

Import trace for requested module:
./node_modules/@opentelemetry/instrumentation-connect/build/src/enums/AttributeNames.js
./node_modules/@opentelemetry/instrumentation-connect/build/src/index.js
./node_modules/@sentry/node/build/cjs/integrations/tracing/connect.js
./node_modules/@sentry/node/build/cjs/index.js
./node_modules/@sentry/nextjs/build/cjs/index.server.js
./src/app/page.tsx

./node_modules/@opentelemetry/instrumentation-connect/build/src/index.js
Self-reference dependency has unused export name: This should not happen

Import trace for requested module:
./node_modules/@opentelemetry/instrumentation-connect/build/src/index.js
./node_modules/@sentry/node/build/cjs/integrations/tracing/connect.js
./node_modules/@sentry/node/build/cjs/index.js
./node_modules/@sentry/nextjs/build/cjs/index.server.js
./src/app/page.tsx

./node_modules/@opentelemetry/instrumentation-dataloader/build/src/index.js
Self-reference dependency has unused export name: This should not happen

Import trace for requested module:
./node_modules/@opentelemetry/instrumentation-dataloader/build/src/index.js
./node_modules/@sentry/node/build/cjs/integrations/tracing/dataloader.js
./node_modules/@sentry/node/build/cjs/index.js
./node_modules/@sentry/nextjs/build/cjs/index.server.js
./src/app/page.tsx


> Build failed because of webpack errors
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Nov 11, 2024
@DavidHaintz
Copy link
Author

I found how to fix it.
layout.tsx may not be client-side. If you need client-side code in your layout, move it into a seperate component (which you can mark as client) and wrap it inside layout.tsx.

Now everything works.

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

No branches or pull requests

1 participant