Skip to content

@sentry/nextjs 6.7.1+ withSentryConfig static site generation fails if Next publicRuntimeConfig is called  #3761

Closed
@neilpoulin

Description

@neilpoulin

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/nextjs

Version:

# @sentry/nextjs
6.8.0 and 6.7.2 (works in 6.7.1)

# next
11.0.1

Description

Running next build fails on all statically generated pages that depend on Next's publicRuntimeConfig as it is undefined.

Everything works great on @sentry/nextjs version 6.7.1 but static site builds break on both 6.7.2 and 6.8.0.

If i exclude the withSentryConfig plugin from my next.config.js file, the app builds successfully.

Note: JIT logs come from tailwind css, using version 2.2.4.

Build logs

/Users/neilpoulin/.nvm/versions/node/v12.18.4/bin/node /Users/neilpoulin/.nvm/versions/node/v12.18.4/lib/node_modules/npm/bin/npm-cli.js run build:dry --scripts-prepend-node-path=auto

> [email protected] build:dry /Users/repos/my-sentry-project
> NODE_ENV=production SENTRY_DRY_RUN=true next build

info  - Loaded env from /Users/repos/my-sentry-project/.env.local
info  - Loaded env from /Users/repos/my-sentry-project/.env
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types  

warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
[=== ] info  - Generating static pages (0/11)
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot destructure property 'accessTokenExpirationRefreshBufferMs' of 'publicRuntimeConfig' as it is undefined.
    at getConfig (/Users/repos/my-sentry-project/.next/server/chunks/4863.js:138:5)
    at Object.1329 (/Users/repos/my-sentry-project/.next/server/chunks/9134.js:4082:48)
    at __webpack_require__ (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:25:42)
    at Object.9569 (/Users/repos/my-sentry-project/.next/server/chunks/9134.js:3789:12)
    at __webpack_require__ (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:25:42)
    at Object.349 (/Users/repos/my-sentry-project/.next/server/pages/_app.js:175:13)
    at __webpack_require__ (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:25:42)
    at __webpack_exec__ (/Users/repos/my-sentry-project/.next/server/pages/_app.js:834:52)
    at /Users/repos/my-sentry-project/.next/server/pages/_app.js:835:90
    at Function.__webpack_require__.X (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:108:21)
[==  ] info  - Generating static pages (0/11)
Error occurred prerendering page "/privacy-policy". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot destructure property 'accessTokenExpirationRefreshBufferMs' of 'publicRuntimeConfig' as it is undefined.
    at getConfig (/Users/repos/my-sentry-project/.next/server/chunks/4863.js:138:5)
    at Object.1329 (/Users/repos/my-sentry-project/.next/server/chunks/9134.js:4082:48)
    at __webpack_require__ (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:25:42)
    at Object.9569 (/Users/repos/my-sentry-project/.next/server/chunks/9134.js:3789:12)
    at __webpack_require__ (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:25:42)
    at Object.349 (/Users/repos/my-sentry-project/.next/server/pages/_app.js:175:13)
    at __webpack_require__ (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:25:42)
    at __webpack_exec__ (/Users/repos/my-sentry-project/.next/server/pages/_app.js:834:52)
    at /Users/repos/my-sentry-project/.next/server/pages/_app.js:835:90
    at Function.__webpack_require__.X (/Users/repos/my-sentry-project/.next/server/webpack-runtime.js:108:21)



#### .... etc, for all static pages on the site

Next.js config file

/* eslint-disable @typescript-eslint/no-var-requires */
const withBundleAnalyzer = require('@next/bundle-analyzer')({
    enabled: process.env.ANALYZE === 'true',
});
const { withSentryConfig } = require('@sentry/nextjs');

const isProd = process.env.NODE_ENV === 'production';
const isDryRun = process.env.SENTRY_DRY_RUN === 'true';

// Note: the Sentry Deploy is now triggered in circleci
const SentryWebpackPluginOptions = {
    dryRun: !isProd || isDryRun,
    debug: true,
    authToken: process.env.SENTRY_AUTH_TOKEN,
    setCommits: {
        commit: process.env.APP_VERSION,
        repo: process.env.SENTRY_REPO,
    },
};

/** @type {import('next/dist/next-server/server/config').NextConfig} **/
const nextConfig = {
    target: 'server',
    poweredByHeader: false,
    productionBrowserSourceMaps: true,
    publicRuntimeConfig: {
        apiHost: process.env.API_HOST,
        accessTokenExpirationRefreshBufferMs: process.env.ACCESS_TOKEN_EXPIRATION_REFRESH_BUFFER_MS,
        // ... etc
    },
};

const sentryConfig = isProd ? withSentryConfig(nextConfig, SentryWebpackPluginOptions) : nextConfig;

module.exports = withBundleAnalyzer(sentryConfig);

Related issues?

#3733

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions