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: Can't resolve '@sentry/utils' with Next.js (app router), pnpm #14316

Closed
3 tasks done
bernardoforcillo opened this issue Nov 15, 2024 · 5 comments
Closed
3 tasks done
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@bernardoforcillo
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.38.0

Framework Version

React 18.3.1 Next.js 14.2.16

Link to Sentry event

No response

Reproduction Example/SDK Setup

// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: 'https://48f482fd599c8c9c69660053eccd765f@o4508054239838208.ingest.de.sentry.io/4508161681129552',

  enabled: process.env.NODE_ENV === 'production',

  // Add optional integrations for additional features
  integrations: [Sentry.replayIntegration()],

  // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
  tracesSampleRate: 1,

  // Define how likely Replay events are sampled.
  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,

  // Define how likely Replay events are sampled when an error occurs.
  replaysOnErrorSampleRate: 1.0,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// The config you add here will be used whenever one of the edge features is loaded.
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: 'https://48f482fd599c8c9c69660053eccd765f@o4508054239838208.ingest.de.sentry.io/4508161681129552',

  enabled: process.env.NODE_ENV === 'production',

  // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
  tracesSampleRate: 1,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: 'https://48f482fd599c8c9c69660053eccd765f@o4508054239838208.ingest.de.sentry.io/4508161681129552',

  enabled: process.env.NODE_ENV === 'production',

  // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
  tracesSampleRate: 1,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

/// Nextjs config:

import { withSentryConfig } from '@sentry/nextjs';
import createNextIntlPlugin from 'next-intl/plugin';
import withBundleAnalyzer from '@next/bundle-analyzer';

const withNextIntl = createNextIntlPlugin('./src/scripts/i18n/request.ts');

const withAnalyzer = withBundleAnalyzer({
  enabled: process.env.NEXT_ANALYZE === 'true',
});

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
  reactStrictMode: true,
  compiler: {
    reactRemoveProperties: true,
  },
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '*.googleusercontent.com',
        port: '',
        pathname: '/a/**',
      },
    ],
  },
};

const withSentry = withSentryConfig(withNextIntl(nextConfig), {
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options

  org: 'easywhey',
  project: 'platform-nextjs',

  // Only print logs for uploading source maps in CI
  silent: !process.env.CI,

  // For all available options, see:
  // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

  // Upload a larger set of source maps for prettier stack traces (increases build time)
  widenClientFileUpload: true,

  // Automatically annotate React components to show their full name in breadcrumbs and session replay
  reactComponentAnnotation: {
    enabled: true,
  },

  // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
  // This can increase your server load as well as your hosting bill.
  // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
  // side errors will fail.
  tunnelRoute: '/monitoring',

  // Hides source maps from generated client bundles
  hideSourceMaps: true,

  // Automatically tree-shake Sentry logger statements to reduce bundle size
  disableLogger: true,

  // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
  // See the following for more information:
  // https://docs.sentry.io/product/crons/
  // https://vercel.com/docs/cron-jobs
  automaticVercelMonitors: true,
});

export default withAnalyzer(withSentry);

Steps to Reproduce

Build via pnpm next build works, via podman does not

FROM node:20-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN pnpm install -g turbo
FROM base AS deps
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
RUN pnpm install -g turbo
COPY . . 
RUN turbo prune @easywhey/platform --docker
FROM base AS builder
RUN apk update
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY --from=deps /app/out/json/ .
RUN pnpm install --frozen-lockfile
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production
COPY --from=deps /app/out/full/ .
RUN pnpm turbo build --filter=@easywhey/platform...
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder --chown=nextjs:nodejs /app/apps/platform/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/platform/.next/static ./apps/platform/.next/static
COPY --from=builder --chown=nextjs:nodejs /app/apps/platform/public ./apps/platform/public
USER nextjs
EXPOSE 3000
CMD ["node", "apps/app/server.js"]

Expected Result

Build the container

Actual Result

@easywhey/platform:build: cache miss, executing 487442c12d267ce5
@easywhey/platform:build: 
@easywhey/platform:build: > @easywhey/platform@ build /app/apps/platform
@easywhey/platform:build: > next build
@easywhey/platform:build: 
@easywhey/platform:build:   ▲ Next.js 14.2.16
@easywhey/platform:build:   - Environments: .env
@easywhey/platform:build:   - Experiments (use with caution):
@easywhey/platform:build:     · instrumentationHook
@easywhey/platform:build: 
@easywhey/platform:build:    Creating an optimized production build ...
@easywhey/platform:build: Failed to compile.
@easywhey/platform:build: 
@easywhey/platform:build: ./src/app/api/*
@easywhey/platform:build: Module not found: Can't resolve '@sentry/utils'
@easywhey/platform:build: 
@easywhey/platform:build: https://nextjs.org/docs/messages/module-not-found
@easywhey/platform:build: 
@easywhey/platform:build: ./src/app/api/*
@easywhey/platform:build: Module not found: Can't resolve '@sentry/utils'
@easywhey/platform:build: 
@easywhey/platform:build: https://nextjs.org/docs/messages/module-not-found
@easywhey/platform:build: 
@easywhey/platform:build: ./src/app/api/*
@easywhey/platform:build: Module not found: Can't resolve '@sentry/utils'
@easywhey/platform:build: 
@easywhey/platform:build: https://nextjs.org/docs/messages/module-not-found
@easywhey/platform:build: 
@easywhey/platform:build: ./src/app/api/*
@easywhey/platform:build: Module not found: Can't resolve '@sentry/utils'
@easywhey/platform:build: 
@easywhey/platform:build: https://nextjs.org/docs/messages/module-not-found
@easywhey/platform:build: 
@easywhey/platform:build: ./src/app/api/*
@easywhey/platform:build: Module not found: Can't resolve '@sentry/utils'
@easywhey/platform:build: 
@easywhey/platform:build: https://nextjs.org/docs/messages/module-not-found
@easywhey/platform:build: 
@easywhey/platform:build: 
@easywhey/platform:build: > Build failed because of webpack errors
@easywhey/platform:build:  ELIFECYCLE  Command failed with exit code 1.
@easywhey/platform:build: ERROR: command finished with error: command (/app/apps/platform) /usr/local/bin/pnpm run build exited (1)
@easywhey/platform#build: command (/app/apps/platform) /usr/local/bin/pnpm run build exited (1)

Seem like the bug effect only /api/* routes.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 15, 2024
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Nov 15, 2024
@bernardoforcillo
Copy link
Author

@lforst i created a new issue

@lforst
Copy link
Member

lforst commented Nov 15, 2024

Hi, unfortunately we lack things to exactly reproduce your issue. Would you mind creating a minimal reproduction example we can actually run? Thank you!

@bernardoforcillo
Copy link
Author

@lforst
Copy link
Member

lforst commented Nov 19, 2024

Hi, since the build is working outside of docker I think this is not something we can solve. You need to adjust your Dockerfile to correctly include all the dependencies.

@bernardoforcillo
Copy link
Author

Hi @lforst thanks, this kind of bug is only happening on local container build. I retried running a github action and it built fine.

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

2 participants