Skip to content

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined #5478

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

Closed
3 tasks done
wadehammes opened this issue Jul 27, 2022 · 17 comments · Fixed by #5479
Closed
3 tasks done
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@wadehammes
Copy link

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which package are you using?

@sentry/nextjs

SDK Version

7.8.0

Framework Version

7.8.0

Link to Sentry event

No response

Steps to Reproduce

Use latest Sentry with NextJS

Expected Result

Should behave like 7.7.0 and not throw an error when building

Actual Result

image

@AbhiPrasad
Copy link
Member

Hey thanks for writing in. That looks like a problem we should fix. To help us debug, could you tell us your next + webpack version, and show us your next.config.js file?

@AbhiPrasad AbhiPrasad added Status: Needs Information Package: nextjs Issues related to the Sentry Nextjs SDK labels Jul 27, 2022
@wadehammes
Copy link
Author

Next 12.1.6 (the webpack version bundled with that)

const SentryWebpackPlugin = require("@sentry/webpack-plugin");

const withTM = require("next-transpile-modules")([
  "@mui/material",
  "@mui/system",
]);

module.exports = withTM({
  productionBrowserSourceMaps: true,
  outputFileTracing: false,
  compiler: {
    // ssr and displayName are configured by default
    styledComponents: true,
    reactRemoveProperties: false,
  },
  images: {
    domains: [
      "images.ctfassets.net",
      "assets.ctfassets.net",
      "videos.ctfassets.net",
      "assets.zappyride.com",
    ],
  },
  i18n: {
    locales: ["en", "es"],
    defaultLocale: "en",
  },
  env: {
    CONTENTFUL_SPACE_ID: process.env.CONTENTFUL_SPACE_ID,
    CONTENTFUL_API_TOKEN: process.env.CONTENTFUL_API_TOKEN,
    CONTENTFUL_PREVIEW_TOKEN: process.env.CONTENTFUL_PREVIEW_TOKEN,
    CONTENTFUL_PREVIEW_SECRET: process.env.CONTENTFUL_PREVIEW_SECRET,
    ENVIRONMENT: process.env.ENVIRONMENT,
    GA_TRACKING_ID: process.env.GA_TRACKING_ID,
    GA_GTM_PREVIEW_ENV: process.env.GA_GTM_PREVIEW_ENV,
    GA_GTM_AUTH: process.env.GA_GTM_AUTH,
    NEXT_PUBLIC_SENTRY_DSN: process.env.NEXT_PUBLIC_SENTRY_DSN,
    SEGMENT_ANALYTICS_KEY: process.env.SEGMENT_ANALYTICS_KEY,
    SENTRY_TRACES_SAMPLE_RATE: process.env.SENTRY_TRACES_SAMPLE_RATE,
    SENTRY_AUTH_TOKEN: process.env.SENTRY_AUTH_TOKEN,
    VERCEL_GITHUB_COMMIT_SHA: process.env.VERCEL_GITHUB_COMMIT_SHA,
    FULLSTORY_ORG_ID: process.env.FULLSTORY_ORG_ID,
    API_SECRET: process.env.API_SECRET,
    EMBED_SOCIAL_API_KEY: process.env.EMBED_SOCIAL_API_KEY,
    VERCEL_TEAM_ID: process.env.VERCEL_TEAM_ID,
    VERCEL_API_TOKEN: process.env.VERCEL_API_TOKEN,
    SMARTY_STREETS_WEBKEY: process.env.SMARTY_STREETS_WEBKEY,
    SMARTY_STREETS_AUTH_ID: process.env.SMARTY_STREETS_AUTH_ID,
    SMARTY_STREETS_AUTH_TOKEN: process.env.SMARTY_STREETS_AUTH_TOKEN,
    ZAPPY_RIDE_API_AUTH_KEY: process.env.ZAPPY_RIDE_API_AUTH_KEY,
    LAUNCH_DARKLY_CLIENT_ID: process.env.LAUNCH_DARKLY_CLIENT_ID,
  },
  webpack: (config, options) => {
    if (options.isServer && options.nextRuntime !== "nodejs") return config;

    if (!options.isServer) {
      config.resolve.alias["@sentry/node"] = "@sentry/nextjs";
    }

    // Only add sentry webpack plugin when sentry DSN is defined and the
    // app is being deployed (NODE_ENV=production when making an optimized build
    // for a deployed environment).
    if (
      process.env.NEXT_PUBLIC_SENTRY_DSN &&
      process.env.NODE_ENV === "production"
    ) {
      config.plugins.push(
        new SentryWebpackPlugin({
          authToken: process.env.SENTRY_AUTH_TOKEN,
          include: ".next",
          ignore: ["node_modules"],
          urlPrefix: "~/_next",
          release: process.env.VERCEL_GITHUB_COMMIT_SHA,
          org: "rhythm",
          project: "rhythm-marketing",
        })
      );
    }

    config.resolve.alias = {
      ...config.resolve.alias,
      "@mui/styled-engine": "@mui/styled-engine-sc",
    };

    return config;
  },
  async redirects() {
    if (process.env.ENVIRONMENT === "production") {
      return [
        ...productionRedirects,
        ...sharedRedirects,
        ...oldCampaignRedirects,
      ];
    } else {
      return [...sharedRedirects, ...oldCampaignRedirects];
    }
  },
  async headers() {
    return [
      {
        source: "/",
        headers: [
          {
            key: "Cache-Control",
            value: "s-maxage=1, stale-while-revalidate",
          },
          ...securityHeaders,
        ],
      },
      {
        source: "/:path*",
        headers: [
          {
            key: "Cache-Control",
            value: "s-maxage=1, stale-while-revalidate",
          },
          ...securityHeaders,
        ],
      },
      {
        source: "/fonts/averta-font/(.*)",
        headers: [
          {
            key: "Cache-Control",
            value: "public, max-age=31536000, stale-while-revalidate",
          },
          ...securityHeaders,
        ],
      },
      {
        source: "/fonts/fontface.css",
        headers: [
          {
            key: "Cache-Control",
            value: "public, max-age=31536000, stale-while-revalidate",
          },
          ...securityHeaders,
        ],
      },
    ];
  },
});

// Redirect test and home slug pages on Production
const sources = [
  "/:parent(test-page.*)",
  "/:parent(home.*)",
  "/partner/:slug(test-page.*)",
  "/affiliate/:slug(test-page.*)",
  "/lp/:slug(test-page.*)",
  "/page-preview",
  "/deployments",
  "/hello",
];

const productionRedirects = sources.map((source) => ({
  source,
  destination: "/",
  permanent: true,
}));

const oldCampaignUrls = [
  "/bingo",
  "/breathe",
  "/hardtospell-2",
  "/visa",
  "/cinemark",
];

const oldCampaignRedirects = oldCampaignUrls.map((source) => ({
  source,
  destination: "/",
  permanent: true,
}));

// Redirects various lp directories to home page since they have no page
const lpSources = ["/partner", "/affiliate", "/lp"];

const lpRedirects = lpSources.map((source) => ({
  source,
  destination: "/",
  permanent: true,
}));

const error404Redirects = [
  {
    // 301 Redirect /eswelcome 404
    source: "/eswelcome",
    destination: "/es/welcome",
    permanent: true,
  },
  {
    // 301 Redirect /eswelcome 404
    source: "/es/eswelcome",
    destination: "/es/welcome",
    permanent: true,
  },
  {
    // 301 Redirect /hc/en-us 404
    source: "/hc/en-us",
    destination: "/",
    permanent: true,
  },
  {
    source: "/summer-email",
    destination: "/lp/email-summer",
    permanent: true,
  },
  {
    source: "/email-summer",
    destination: "/lp/email-summer",
    permanent: true,
  },
  {
    source: "/lp/solar-buyback-12",
    destination: "/rooftop-solar-buyback-plan",
    permanent: true,
  },
  {
    source: "/about/and",
    destination: "/about",
    permanent: true,
  },
  {
    source: "/about/a",
    destination: "/about",
    permanent: true,
  },
];

// Redirects needed for both Production and Staging/Development
const sharedRedirects = [
  {
    // 301 Redirect ElectricityPlans page to new affiliate url
    source: "/ep",
    destination: "/affiliate/ep",
    permanent: true,
  },
  {
    // 301 Redirect original simple header page to new lp url
    source: "/texas-sh",
    destination: "/lp/texas-sh",
    permanent: true,
  },
  {
    // 301 Redirect Support pages
    source: "/support",
    destination: "https://support.gotrhythm.com",
    permanent: true,
  },
  {
    // 301 Redirect register pages
    source: "/register",
    destination: "https://app.gotrhythm.com/sign-up?rcid=default",
    permanent: true,
  },
  {
    // 301 Redirect login page
    source: "/login",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect login page
    source: "/sign-in",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect login page
    source: "/account",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect login page
    source: "/myaccount",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect login page
    source: "/my-account",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect register pages
    source: "/sign-up",
    destination: "https://app.gotrhythm.com/sign-up?rcid=default",
    permanent: true,
  },
  {
    // 301 Redirect register pages
    source: "/sign-up/plans",
    destination: "https://app.gotrhythm.com/sign-up?rcid=default",
    permanent: true,
  },
  {
    // 301 Redirect /payments 404
    source: "/payments",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect /payments 404
    source: "/pay-bill",
    destination: "https://app.gotrhythm.com/sign-in",
    permanent: true,
  },
  {
    // 301 Redirect Earth Day
    source: "/lp/texas-earth-day",
    destination: "/electricity/texas",
    permanent: true,
  },
  {
    // 301 Redirect Earth Day
    source: "/lp/fb-earth-day",
    destination: "/electricity/texas",
    permanent: true,
  },
  {
    // 301 Redirect /reviews 404
    source: "/reviews",
    destination: "/about/reviews",
    permanent: true,
  },
  {
    // 301 Redirect /chapman-ranch
    source: "/chapman-ranch",
    destination: "/chapman-ranch-wind-energy-plans-texas",
    permanent: true,
  },
  {
    // 301 Redirect /solar
    source: "/solar",
    destination: "/solar-electricity-plans",
    permanent: true,
  },
  {
    // 301 Redirect /solar-buyback
    source: "/solar-buyback",
    destination: "/rooftop-solar-buyback-plan",
    permanent: true,
  },
  {
    // 301 Redirect /careers
    source: "/careers",
    destination: "/about/careers",
    permanent: true,
  },
  {
    // 301 Redirect /jobs
    source: "/jobs",
    destination: "/about/careers",
    permanent: true,
  },
  {
    // 301 Redirect /rewards 404
    source: "/why-rhythm/rewards",
    destination: "/rewards",
    permanent: true,
  },
  {
    // Redirect /purchase to /purchase/new-vehicles
    source: "/ev/purchase",
    destination: "/ev/purchase/new-vehicles",
    permanent: true,
  },
  {
    // Redirect /terms to /terms-of-use
    source: "/terms",
    destination: "/terms-of-use",
    permanent: true,
  },
  {
    // Redirect /ev/power to /electric-vehicle-plans
    source: "/ev/power",
    destination: "/electric-vehicle-plans",
    permanent: true,
  },
  {
    // Redirect old plans page to new plans overview
    source: "/why-rhythm/electricity-plans",
    destination: "/plans-overview",
    permanent: true,
  },
  {
    // Redirect old home solar buyback to new rooftop solar buyback
    source: "/solar-buyback-plan",
    destination: "/rooftop-solar-buyback-plan",
    permanent: true,
  },
  {
    // Redirect all /electricity SEO pages (including city pages) to new /texas-electricity
    source: "/electricity(.*)",
    destination: "/texas-electricity",
    permanent: true,
  },
  {
    // Redirect all /vs competitor pages to /compare
    source: "/vs(.*)",
    destination: "/compare-texas-electricity-providers",
    permanent: true,
  },
  {
    // Redirect all /mymove to home
    source: "/mymove",
    destination: "/",
    permanent: true,
  },
  {
    source: "/secure",
    destination:
      "/secure2022?utm_source=external-mktg&utm_medium=DM&utm_campaign=ADM_SecureMover_07_2022&utm_content=secure-move-july2022&utm_term=20220705&rcid=simplisafe",
    permanent: true,
  },
  {
    // Redirect /simply-move to new simply-move with query and rcid param
    source: "/simply-move",
    destination:
      "/simply-move2022?rcid=mover-promo-200&utm_content=simplymove-july2022&utm_term=20220705&utm_source=external-mktg&utm_medium=DM&utm_campaign=ADM_SimplyMove200_07_2022",
    permanent: true,
  },
  {
    // Redirect /movers to new movers2022 with query and rcid param
    source: "/movers",
    destination:
      "/movers2022?utm_source=external-mktg&utm_medium=MyMoveDigital&utm_campaign=AWM_MyMoveDigital_07_2022&utm_content=mymove-july2022&utm_term=20220701&rcid=simplisafe",
    permanent: true,
  },
  ...error404Redirects,
  ...lpRedirects,
];

// https://securityheaders.com
const scriptSrc = [
  "'self'",
  "'unsafe-eval'",
  "'unsafe-inline'",
  "*.youtube.com",
  "*.ads-twitter.com",
  "*.twitter.com",
  "*.instagram.com",
  "*.ctfassets.net",
  "*.fullstory.com",
  "*.zdassets.com",
  "*.segment.com",
  "*.facebook.net",
  "*.nextdoor.com",
  "*.tvsquared.com",
  "*.doubleclick.net",
  "*.adsrvr.org",
  "*.bing.com",
  "*.google.com",
  "*.google-analytics.com",
  "*.googletagmanager.com",
  "*.googleadservices.com",
  "*.googleusercontent.com",
  "polyfill.io",
  "*.vercel-insights.com",
  "*.vercel.app",
  "embedsocial.com",
  "*.abtasty.com",
  "*.smooch.io",
  "*.mypurecloud.com",
  "*.cloudfront.net",
  "*.cobrowse.io",
  "*.redditstatic.com",
  "*.clarity.ms",
  "aa.trkn.us",
  "*.hotjar.com",
  "*.adnxs.com",
  "*.shop.pe",
  "addshoppers.s3.amazonaws.com",
  "cdn.id5-sync.com",
];

const ContentSecurityPolicy = `
  default-src 'self';
  script-src ${scriptSrc.join(" ")};
  child-src *.youtube.com *.google.com *.twitter.com *.facebook.com *.adsrvr.org *.doubleclick.net embedsocial.com *.abtasty.com;
  style-src 'self' 'unsafe-inline' *.googleapis.com *.google.com *.googletagmanager.com embedsocial.com *.abtasty.com;
  img-src * blob: data: *.ctfassets.net *.fbsbx.com *.googleusercontent.com *.abtasty.com smart-pixl.com *.fullstory.com;
  object-src * blob: data:;
  media-src 'self' *.zdassets.com *.ctfassets.net *.abtasty.com;
  connect-src *;
  frame-src * 'self' blob: data: *.ctfassets.net *.abtasty.com;
  font-src 'self' data: fonts.gstatic.com *.abtasty.com *.cloudflare.com;
  worker-src 'self' *.vercel.app;
  manifest-src 'self' *.vercel.app;
`;

const securityHeaders = [
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
  {
    key: "Content-Security-Policy",
    value: ContentSecurityPolicy.replace(/\n/g, ""),
  },
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
  {
    key: "Referrer-Policy",
    value: "strict-origin-when-cross-origin",
  },
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
  {
    key: "X-Frame-Options",
    value: "SAMEORIGIN",
  },
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
  {
    key: "X-Content-Type-Options",
    value: "nosniff",
  },
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control
  {
    key: "X-DNS-Prefetch-Control",
    value: "on",
  },
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
  {
    key: "Strict-Transport-Security",
    value: "max-age=31536000; includeSubDomains; preload",
  },
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
  {
    key: "Permissions-Policy",
    value: "camera=(), microphone=(), geolocation=(), interest-cohort=()",
  },
];

@AbhiPrasad

@AbhiPrasad
Copy link
Member

Why are you using the sentry WebpackPlugin stand-alone? Using withSentryConfig as per https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#extend-nextjs-configuration is what we recommend (it’ll include the webpack plug-in under the hood automatically)

@wadehammes
Copy link
Author

@AbhiPrasad trying this now, this is old code so a refactor is always appreciated. I'll let you know results here soon.

@vip30
Copy link

vip30 commented Jul 28, 2022

I'm using withSentryConfig and facing the same issue as well

@wadehammes
Copy link
Author

@AbhiPrasad updated to the above and seems to be building now in production. Not sure what changed between today and yesterday (tried reverting back to 7.7.0 first to make sure and it also failed with same error). Could be that Next updated their 16.x node version which might have had some breaking changes potentially?

@lobsterkatie
Copy link
Member

lobsterkatie commented Jul 28, 2022

@wadehammes - glad to hear it's working now! I can see what's failing (and will add a safety check around it), and indeed, there was a change released in 7.8.0 which touches that code path. The fact that it was still erroring when you reverted to 7.7.0 is very curious, though, and obv would mean the change in question wasn't the cause. When you did that, had you already made the withSentryConfig change?

@vip30 - Can you also please share your nextjs version and next.config.js code? Also, can you similarly try reverting to 7.7.0 to see if the error still happens there, as was the case for @wadehammes?

@wadehammes
Copy link
Author

@lobsterkatie @AbhiPrasad the new withSentryConfig setup is working great but now our hero Lottie won't load (but only on the home page weirdly) due to the baggage header. Trying to figure out why only this asset won't load but not all the others.

https://www.gotrhythm.com/

image

@wadehammes
Copy link
Author

@wadehammes - glad to hear it's working now! I can see what's failing (and will add a safety check around it), and indeed, there was a change released in 7.8.0 which touches that code path. The fact that it was still erroring when you reverted to 7.7.0 is very curious, though, and obv would mean the change in question wasn't the cause. When you did that, had you already made the withSentryConfig change?

@vip30 - Can you also please share your nextjs version and next.config.js code? Also, can you similarly try reverting to 7.7.0 to see if the error still happens there, as was the case for @wadehammes?

I had not updated to the withSentryConfig yet, I wanted to determine if 7.8.0 was the cause. It could have been a caching issue with Vercel though potentially?

@wadehammes
Copy link
Author

Even weirder, the asset in question loads on our staging url (NextJS Preview env) which is the exact same release as production right now.

image

@lobsterkatie
Copy link
Member

@wadehammes - glad to hear it's working now! I can see what's failing (and will add a safety check around it), and indeed, there was a change released in 7.8.0 which touches that code path. The fact that it was still erroring when you reverted to 7.7.0 is very curious, though, and obv would mean the change in question wasn't the cause. When you did that, had you already made the withSentryConfig change?
@vip30 - Can you also please share your nextjs version and next.config.js code? Also, can you similarly try reverting to 7.7.0 to see if the error still happens there, as was the case for @wadehammes?

I had not updated to the withSentryConfig yet, I wanted to determine if 7.8.0 was the cause. It could have been a caching issue with Vercel though potentially?

Maybe? Though I've never seen that happen, even when deploying slightly different versions of the SDK over and over again in rapid succession (as I did more times than I can count when building the SDK!). Might just be gremlins...

As for the baggage header, is that problem new with 7.8.0 as well? And do the assets which load successfully also come from assets.ctfassets.net, or only the failing one?

@wadehammes
Copy link
Author

@lobsterkatie yes all assets are from Contentful's asset CDN. For example, https://www.gotrhythm.com/plans-overview

@lobsterkatie
Copy link
Member

@lobsterkatie yes all assets are from Contentful's asset CDN. For example, gotrhythm.com/plans-overview

That is indeed strange. And does this also happen with 7.7.0, or no?

@wadehammes
Copy link
Author

@lobsterkatie actually this is 7.7.0 right now, let me try 7.8.0 now

@wadehammes
Copy link
Author

That actually was 7.8.0 😅 sorry it's too late for me to be working

@wadehammes
Copy link
Author

Updated some CORS headers on my end in my next.config and seem to have resolved it. Looking forward to the patch above!

@vip30
Copy link

vip30 commented Jul 28, 2022

@wadehammes - glad to hear it's working now! I can see what's failing (and will add a safety check around it), and indeed, there was a change released in 7.8.0 which touches that code path. The fact that it was still erroring when you reverted to 7.7.0 is very curious, though, and obv would mean the change in question wasn't the cause. When you did that, had you already made the withSentryConfig change?

@vip30 - Can you also please share your nextjs version and next.config.js code? Also, can you similarly try reverting to 7.7.0 to see if the error still happens there, as was the case for @wadehammes?

Here is the nextjs config and yes 7.7.0 is working, just not working in 7.8.0

const path = require("path");
const relayConfig = require("./relay.config");
const WebpackAliyunOssPlugin = require("webpack-aliyun-oss");
const withInterceptStdout = require("next-intercept-stdout");
const withPWA = require("next-pwa");
const { withSentryConfig } = require("@sentry/nextjs");

// Get environment variables
const cdnHost = process.env.OSS_HOST;
const envSlug = process.env.ENV_SLUG;
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL;
const useCDN = process.env.USE_CDN === "true";
const useSourceMap = process.env.USE_SOURCE_MAP === "true";
const oss = {
  bucket: process.env.OSS_BUCKET_NAME || "",
  keyId: process.env.OSS_ACCESS_KEY_ID || "",
  keySecret: process.env.OSS_ACCESS_KEY_SECRET || "",
  region: process.env.OSS_REGION || "",
};

/** @type {import('next').NextConfig} */
let nextConfig = {
  assetPrefix: useCDN ? `https://${cdnHost}/${envSlug}` : "",
  compiler: {
    emotion: true,
    relay: relayConfig,
    reactRemoveProperties: false,
  },
  experimental: {
    runtime: "experimental-edge",
    serverComponents: true,
    esmExternals: "loose",
  },
  pageExtensions: ["page.tsx", "page.ts", "page.jsx", "page.js"],
  productionBrowserSourceMaps: useSourceMap,
  useFileSystemPublicRoutes: false,
  images: {
    domains: ["cdn.i-scmp.com", "img.i-scmp.com"],
  },
  swcMinify: true,
  reactStrictMode: true,
  sentry: {
    disableServerWebpackPlugin: process.env.SENTRY_DISABLE_WEBPACK_PLUGIN === "true",
    disableClientWebpackPlugin: process.env.SENTRY_DISABLE_WEBPACK_PLUGIN === "true",
  },
  webpack: (config, { dev, isServer, webpack }) => {
    // Set alias in webpack
    config.resolve.alias = {
      ...config.resolve.alias,
      "~": __dirname,
    };

    // add svg loader
    config.module.rules.push({
      test: /\.svg$/i,
      issuer: /\.[jt]sx?$/,
      use: [
        {
          loader: "@svgr/webpack",
          options: {
            svgoConfig: {
              plugins: [
                {
                  name: "removeViewBox",
                  active: false,
                },
              ],
            },
          },
        },
      ],
    });
    if (!isServer) {
      useCDN &&
        config.plugins.push(
          new WebpackAliyunOssPlugin({
            from: [".next/static/**", "public/sw.**"],
            accessKeyId: oss.keyId,
            accessKeySecret: oss.keySecret,
            bucket: oss.bucket,
            region: oss.region,
            overwrite: true,
            setOssPath(filePath) {
              // Need to replace the path from ${pwd}/.next to _next/
              // ref: https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix
              return `/${envSlug}/${filePath
                .replace(path.join(process.cwd(), "public"), "public")
                .replace(path.join(process.cwd(), ".next"), "_next")}`;
            },
            setHeaders() {
              return {
                "Access-Control-Allow-Origin": siteUrl,
                Vary: "Origin, Access-Control-Request-Headers, Access-Control-Request-Method",
                "Cache-Control": "max-age=31536000",
              };
            },
          }),
        );
      // Replace existing vendor config
      // ref: https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack-config.ts#L760
      if (!dev) {
        config.optimization.splitChunks.cacheGroups.lib.test = module => {
          return /node_modules[/\\]/.test(module.nameForCondition() || "");
        };
        config.optimization.splitChunks.cacheGroups.lib.name = module => {
          const packageName = module
            .nameForCondition()
            .match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
          return `yarn.${packageName.replaceAll("@", "")}`;
        };
      }
      // Ensures no server modules are included on the client.
      config.plugins.push(new webpack.IgnorePlugin({ resourceRegExp: /@*.\.server$/ }));
    }
    return config;
  },
};

// For removing duplicate atom key in the server stdout
// ref: https://github.com/facebookexperimental/Recoil/issues/733#issuecomment-729255961
nextConfig = withInterceptStdout(nextConfig, text =>
  text.includes("Duplicate atom key") ? "" : text,
);

nextConfig = withPWA({
  ...nextConfig,
  pwa: {
    dest: "public",
    disable: process.env.NODE_ENV !== "production",
    swSrc: "lib/service-worker/index.ts",
  },
});

module.exports = withSentryConfig(nextConfig, {
  release: process.env.NEXT_PUBLIC_COMMIT_SHA,
});

lobsterkatie added a commit that referenced this issue Jul 28, 2022
…5479)

In #5445, a change was made to the way the global `RewriteFrames` helper value is handled. Specifically, setting the default value (using the `||` operator) was moved to the place where the value is set rather than where it's retrieved. But if something goes wrong and for whatever reason the value never gets set globally, it now causes errors when the value is later used, because it has nothing to default to.

This fixes that by restoring the default value to the old location, so that when it's used, it will never be undefined.

Fixes #5478.
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
None yet
Development

Successfully merging a pull request may close this issue.

4 participants