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

Error [ERR_REQUIRE_ESM] Build error in Next Config @sentry/nextjs #13163

Closed
3 tasks done
WebAiz opened this issue Aug 2, 2024 · 2 comments
Closed
3 tasks done

Error [ERR_REQUIRE_ESM] Build error in Next Config @sentry/nextjs #13163

WebAiz opened this issue Aug 2, 2024 · 2 comments
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Stale Type: Bug

Comments

@WebAiz
Copy link

WebAiz commented Aug 2, 2024

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nextjs

SDK Version

^8.17.0

Framework Version

Next 14.1.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

import { withSentryConfig } from "@sentry/nextjs";

// next.config.mjs
/** @type {import('next').NextConfig} */

const nextConfig = {
  basePath: "/notification-center",
  i18n: {
    locales: ["ru", "kz", "en"],
    defaultLocale: "kz",
    localeDetection: false,
  },
  async headers() {
    return [
      {
        // Append the "Service-Worker-Allowed" header
        // to each response, overriding the default worker's scope.
        source: "/(.*)",
        headers: [
          {
            key: "Service-Worker-Allowed",
            value: "/",
          },
          { key: "Access-Control-Allow-Origin", value: "*" }, // replace this your actual origin
        ],
      },
    ];
  },
  optimizeFonts: false,
};

export default withSentryConfig(nextConfig, {
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options

  org: "sentry",
  project: process.env.NEXT_PUBLIC_SENTRY_PROJECT,
  url: process.env.NEXT_PUBLIC_PROJECT_HOST,

  // 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,

  // Transpiles SDK to be compatible with IE11 (increases bundle size)
  transpileClientSDK: true,

  // Uncomment to 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,

  // An auth token is required for uploading source maps.
  authToken: process.env.NEXT_PUBLIC_SENTRY_AUTH_TOKEN,
});

Steps to Reproduce

Our project built when using version ^8.17.0 however it started crashing in our pipelines. Locally the build is successfull

Expected Result

The build should work as before.

Actual Result

> next build 
⨯ Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error
> Build error occurred
Error [ERR_REQUIRE_ESM]: require() of ES Module /ansi-styles/index.js from /@sentry/nextjs/node_modules/chalk/source/index.js not supported.
Instead change the require of /ansi-styles/index.js in /@sentry/nextjs/node_modules/chalk/source/index.js to a dynamic import() which is available in all CommonJS modules.
    at mod.require (/next/dist/server/require-hook.js:65:28)
    at Object.<anonymous> (/@sentry/nextjs/node_modules/chalk/source/index.js:2:20)
    at mod.require (/next/dist/server/require-hook.js:65:28)
    at Object.<anonymous> (/@sentry/nextjs/build/cjs/config/webpack.js:12:15)
    at mod.require (/next/dist/server/require-hook.js:65:28)
    at Object.<anonymous> (/@sentry/nextjs/build/cjs/config/withSentryConfig.js:10:17)
    at mod.require (/next/dist/server/require-hook.js:65:28)
    at Object.<anonymous> (/@sentry/nextjs/build/cjs/index.server.js:3:26) {
  code: 'ERR_REQUIRE_ESM'
}
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Aug 2, 2024
@WebAiz WebAiz changed the title Build error in Next Config @sentry/nextjs Error [ERR_REQUIRE_ESM] Build error in Next Config @sentry/nextjs Aug 2, 2024
@Lms24
Copy link
Member

Lms24 commented Aug 2, 2024

Hey @WebAiz thanks for writing in!

Our project built when using version ^8.17.0 however it started crashing in our pipelines. Locally the build is successfull

If building it locally works, I recommend checking what you do differently in your pipelines where the build fails.

I'm a bit surprised that this is happening now, given we've been using chalk (which depends on ansi-styles) for years. I'm not saying that there's not a bug on our end, just wanna make sure it's not a build config problem first.

@getsantry
Copy link

getsantry bot commented Aug 24, 2024

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Aug 24, 2024
@getsantry getsantry bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2024
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 Stale Type: Bug
Projects
Archived in project
Development

No branches or pull requests

2 participants