Skip to content

Sentry with async function nextConfig not working #7444

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
AbhiPrasad opened this issue Mar 13, 2023 Discussed in #7433 · 1 comment · Fixed by #8721
Closed

Sentry with async function nextConfig not working #7444

AbhiPrasad opened this issue Mar 13, 2023 Discussed in #7433 · 1 comment · Fixed by #8721
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@AbhiPrasad
Copy link
Member

Discussed in #7433

Originally posted by Supermog March 13, 2023
So I have a project that I added Sentry to, but the problem is that I have the nextConfig variable as an async function which the withSentryConfig doesn't accept. My next.config.js file looks like this:

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

const prismic = require('@prismicio/client');

const sm = require('./sm.json');

/** @type {import('next').NextConfig} */
const nextConfig = async () => {
  const client = prismic.createClient(sm.apiEndpoint);

  const repository = await client.getRepository();
  const locales = repository.languages.map(lang => lang.id);

  return {
    reactStrictMode: true,
    swcMinify: true,
    compiler: {
      styledComponents: true,
    },
    i18n: {
      // These are all the locales you want to support in
      // your application
      locales: locales,
      // This is the default locale you want to be used when visiting
      // a non-locale prefixed path e.g. `/hello`
      defaultLocale: locales[0],
      localeDetection: false,
    },
  };
};

module.exports = withSentryConfig(
  nextConfig,
  { silent: true },
  { hideSourcemaps: true },
);

I've also played around with it and using await on the nextConfig argument or calling the function also does not work. I've tried converting it to .then blocks but that also does not work.
Without Sentry it works well because nextjs accepts nextConfig as an async function but Sentry does not. Is there a workaround to this?

"@sentry/nextjs": "^7.42.0",
"next": "13.1.2",
"react": "18.2.0",

@AbhiPrasad AbhiPrasad added Type: Bug Package: nextjs Issues related to the Sentry Nextjs SDK labels Mar 13, 2023
@AbhiPrasad
Copy link
Member Author

From @Supermog

#7433 (reply in thread)

error - Error: Invalid locale returned from getStaticPaths for /[uid], the locale en-gb is not specified in next.config.js
   at /home/supermog/Repos/marketing-cms/node_modules/next/dist/build/utils.js:667:23
   at Array.forEach (<anonymous>)
   at Object.buildStaticPaths (/home/supermog/Repos/marketing-cms/node_modules/next/dist/build/utils.js:621:17)
   at processTicksAndRejections (node:internal/process/task_queues:96:5) {
 type: 'Error',
 page: '/[uid]'
}

This is the error message. It occurs whenever I go to a URL that the 404.tsx component should handle.

@lforst lforst self-assigned this Jul 31, 2023
kamilogorek added a commit that referenced this issue Aug 2, 2023
Modified one template to use the async function instead, as adding an
additional variant to an already bloated integration test runner felt
meh.

Note that type from
#7444 is incorrect.
It should be:

```js
const nextConfig = async () => {
  /** @type {import('next').NextConfig} */
  return {};
}
```

and not:

```js
/** @type {import('next').NextConfig} */
const nextConfig = async () => {
  return {};
}
```

Note #2: async function handling works for `next >= 12.1` only:
https://nextjs.org/docs/app/api-reference/next-config-js/pageExtensions

Verified the behavior locally using provided sample config from the
original issue.

Fixes #7444
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.

3 participants