getsentry / sentry-javascript

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

Netlify build failing if target in `next.config.js` changed to `experimental-serverless-trace` #3932

Closed ani4aniket closed 3 years ago

ani4aniket commented 3 years ago

Package + Version

Version:

"@sentry/nextjs": "^6.11.0"

Description

Describe your issue in detail, ideally, you have a reproducible demo that you can show. When the target in next.config.js from serverless to experimental-serverless-trace, in the resolution of https://github.com/getsentry/sentry-javascript/issues/3575, Netlify build is failing, throws an error: Cannot find module '@prisma/client'

Netlify Logs: https://pastebin.com/6bExettA

next.config.js

const { withSentryConfig } = require('@sentry/nextjs');
const moduleExports = {
  /* config options here */
  target: 'experimental-serverless-trace',
  env: {
    API_ENDPOINT: process.env.API_ENDPOINT,
  },
  webpack5: false,
  webpack(config, { isServer, dev: isDevelopmentMode }) {
    config.module.rules.push({
      test: /\.svg$/,
      issuer: {
        test: /\.(js|ts)x?$/,
      },
      use: [
        {
          loader: '@svgr/webpack',
          // https://react-svgr.com/docs/options/
        },
      ],
    });

    config.module.rules.push({
      test: /\.po$/,
      use: [
        {
          loader: 'ignore-loader',
        },
      ],
    });

    // Fixes npm packages that depend on `fs` module
    if (!isServer) {
      config.node = {
        fs: 'empty',
      };
    }

    // Attempt to ignore storybook files when doing a production build,
    // see also: https://github.com/vercel/next.js/issues/1914
    if (!isDevelopmentMode) {
      config.module.rules.push({
        test: /\.stories.(js|tsx?)/,
        loader: 'ignore-loader',
      });
    }
    return config;
  },
  poweredByHeader: false,
  images: {
    domains: ['unsplash.com'],
  },
};

const SentryWebpackPluginOptions = {
  silent: true,
};

module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
zgreen commented 3 years ago

Seeing a similar error with this next.config.js (generated by the sentry wizard):

const { withSentryConfig } = require("@sentry/nextjs");

const SentryWebpackPluginOptions = {
  // Additional config options for the Sentry Webpack plugin. Keep in mind that
  // the following options are set automatically, and overriding them is not
  // recommended:
  //   release, url, org, project, authToken, configFile, stripPrefix,
  //   urlPrefix, include, ignore

  silent: true, // Suppresses all logs
  // For all available options, see:
  // https://github.com/getsentry/sentry-webpack-plugin#options.
};

const config = {
  reactStrictMode: true,
};
module.exports = withSentryConfig(config, SentryWebpackPluginOptions);

And the Netlify build error:

11:17:44 AM: ModuleNotFoundError: Module not found: Error: Can't resolve 'webpack' in '/opt/build/repo/node_modules/@next/react-refresh-utils'

Is it possible to just use @sentry/react for Netlify builds? Given that these are static builds anyway I'm not sure there's much/any value added by using the custom @sentry/next package.

Thanks!

github-actions[bot] commented 3 years ago

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 label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


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

albin-woto commented 2 years ago

I have the same issue Cannot find module 'webpack' with this next.config.js on Netlify, even if a don't set a target the same error occurs. I didn't had this issue before setting sentry on the project.


const moduleExports = { target: 'experimental-serverless-trace' }

const sentryWebpackPluginOptions = {
  silent: true,
}

module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions)

Currently using "@sentry/nextjs": "^6.14.1"